+ 1
How to draw patterns in java like↓
i want these types of patternss logic 1 01 010 1010 01010 1 10 101 1010 10101 please suggest me a logic to draw this kind of patterns
4 Answers
+ 3
for pattern 2:
Scanner scanner = new Scanner(System.in);
System.out.print("Enter n: ");
int n = scanner.nextInt();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
if (j % 2 == 1) {
System.out.print("1 ");
} else {
System.out.print("0 ");
}
}
System.out.println();
}
}
+ 2
it is called pattern printing:
ex:
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
0
for pattern1 or 2??
0
tysm friend...