How to use for loop statement in java program ?

How to use for loop statement in java program ?

Previous Home Next

 

In this program we understand the for loop.

For loop is used in case of iteration.
 
for(int i=0; i<=5;i--){
for(int j=0; j < i; j++)

two for loops are used in this program to print a pyramid

 


public class pyramid {

public static void main(String[] args) {

for(int i=0; i<=5;i--){
for(int j=0; j < i; j++){

System.out.print("*");

}
}
}

}


*
* *
* * *
* * * *
* * * * *
Previous Home Next