+ 1
How to create looping java code?
How to create code java looping for this output? Output: Input n: 4 * ** *** ****
5 Answers
+ 10
ZULFITRI
Please, go to Code playground,
write one of these solutions and practice!đ
int n = 4;
/*
* Outer loop to handle number of rows
* 'n' in this case.
*/
for (int i = 0; i < n; i++) {
/*
* Inner loop to handle number of
* columns.
* Values changing acc. to outer loop.
*/
for (int j = 0; j <= i; j++) {
// Printing stars.
System.out.print("*");
}
// Ending line after each row.
System.out.println();
}
+ 6
public class Program
{
public static void main(String[] args) {
int number_of_rows = 10;
for(int i = 0; i < number_of_rows; i = i + 1){
for(int n = 0; n < i + 1; n ++){
System.out.print("*");
}
System.out.print("\n");
}
}
}
+ 3
For loop in range from 1 to <=4 as i
Inside another for loop in range from 1 to 1<=i
Inside second for loop:
System.out.print("*");
after second for loop:
System.out.println();
+ 2
try to check this out, it should help.
https://code.sololearn.com/c2UK8ZElW8Er/#java
+ 1
Thanks for answers