Example: 1 ** 123 **** 12345
Answer :
public class Pattern123 {
public static void main(String[] args) {
//i for row and j for column
for(int i=1;i<6;i++){
for(int j=1;j<=i;j++){
if(i%2==0){ //Every even row will print *
System.out.print("*");
}
else{
System.out.print(j);
}
}//end of inner for loop
System.out.println();
}//end of outer for loop
}
}
No comments:
Post a Comment