In the program the following star pattern will be printed.
The program is shown below :
package com.skilledmonster.examples.loops;
public class PyramidNestedForLoopExample_1 {
public static void main(String[] args) {
for(int i=1; i<= 5 ;i++){
for(int j=0; j < i; j++){
// display/add star
System.out.print("*");
}
// generate a new line
System.out.println("");
}
}
}
package com.skilledmonster.examples.loops;public class PyramidNestedForLoopExample_1 { public static void main(String[] args) { for(int i=1; i<= 5 ;i++){ for(int j=0; j < i; j++){ // display/add star System.out.print("*"); } // generate a new line System.out.println(""); } }}
Output :



No comments:
Post a Comment