Java Program for Basic Double Incrementing Triangle Pattern initialised

Printing Basic Double Incrementing Triangle Pattern

In this program we’re going to code basic double incrementing triangle star pattern program .

In this program we will take input from user as row and col and store it in the variable called as row and col and then take count variable as count=col-1 then take a for loop start from int i=1 ti i<=row and inside this take j=1 to j<=i and inside this take statement to print count variable and then increment count variable as count++ then write line changement statement after the end of main loop

Basic double incrementing Triangle Pattern initialised​

Algorithm:

  • Take input from user as row and col and store in count=col-1
  • Run the i loop from i=1 to i++ for (int i = 1; i <= row; i++) inside this take j loop for (int j = 1; j <= i; j++)
  • Inside this j for loop print count System.out.print(count); and after this write System.out.println(); to change line

Code in Java:

import java.util.Scanner;
public class Pattern1 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("Enter row and col");
		int row = sc.nextInt();
		int col = sc.nextInt();
		int count = col-1;
		for (int i = 1; i <= row; i++) {
			for (int j = 1; j <= i; j++) {
				System.out.print(count);
				count++;
			}
			System.out.println();
		}
	}
}
This code is contributed by Shubham Nigam (Prepinsta Placement Cell Student)

One comment on “Java Program for Basic Double Incrementing Triangle Pattern initialised”