+ 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

9th Jun 2017, 3:36 PM
Sultan Belai
Sultan Belai - avatar
4 ответов
+ 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();         }     }
9th Jun 2017, 3:44 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 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(); }
9th Jun 2017, 3:38 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
0
for pattern1 or 2??
9th Jun 2017, 3:39 PM
Sultan Belai
Sultan Belai - avatar
0
tysm friend...
9th Jun 2017, 3:47 PM
Sultan Belai
Sultan Belai - avatar