Star pattern program to print 5*5 matrix
class pattern1{
public static void main(String[] args) {
for (int i=1; i<=5; i++ ) { // Loop to print row
for (int j=1; j<=5; j++ ) { // Loop to print col
System.out.print("* "); // print * in one line
}
System.out.println(" "); // brings the cursor in new line
}
}
}
Output:
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
No comments:
Post a Comment