+ 1
plzz explain how works loop??
int I,j,k; for(i=0;I<10;i++) { for(j=15;j>i;j++) System.out.println(" "); } for(k=0;k<i;k++) { System.out.println(" * "); } System.out.println(" \n");
2 Antworten
+ 6
You had a few mistakes in your code:
int i,j,k;
for(i=0;i<10;i++) {
for(j=15;j>i;j--) {
System.out.print(" ");
}
for(k=0;k<i;k++) {
System.out.print("*");
}
System.out.print("\n");
}
Test it here: https://code.sololearn.com/ceqM5SE0NeKi
Loops are used to repeat a block of instructions while a condition is true.
In a for loop, you have 3 statements that defines it: the first is run only when starting the loop, the second is the condition to loop, and the third is run at the end of each loop, before checking the condition.
For example, in for(i=0;i<10;i++), you begin by initializing the variable i to 0, then you loop (execute the code between the brackets { } again and again) while i < 10, incrementing i by 1 at the end of each loop.
0
tnx zen