+ 1

Got stuck

Question is print the pattern 1 4 1 7 4 1 10 7 4 1 public class Program { public static void main(String[] args) { int a,b,c; for(a=1,a<=10,a++) { for(b=1,b<=a,b--) { c=3; System.out.println(c); } System.out.println(); } } } }

22nd Mar 2022, 9:48 AM
Sageer Khan
Sageer Khan - avatar
3 Antworten
+ 3
there is one parenthesis } at the end in addition, delete the last one use semicolons; in for(;;) istead of commas use two variables a,b first loop is start value 1 to 10 with step 3 second loop are values in line n to 1 with step 3 what is n ?
22nd Mar 2022, 10:42 AM
zemiak
+ 2
Assuming you read input for number of rows <rows> and by taking your example <rows> value were 4. Outer loop initializes counter <i> by 0, repeat while <i> less than <rows>, and increment <i> by 1 in each loop iteration. Inner loop initializes counter <j> by <i> * 3 + 1, repeat while <j> greater than zero, and decrement <j> by 3 in each loop iteration. You print <j> inside the inner loop. You also need to print a line break after the inner loop.
22nd Mar 2022, 11:24 AM
Ipang
0
public class Program { public static void main(String[] args) { int a,b; b=0 for(a=1,a<5, a++) { b+=3 System.out.println(b,1); } } } }
22nd Mar 2022, 9:59 AM
Shadoff
Shadoff - avatar