package demo;
public class DiagonalStar
{
public static void main(String[] args)
{
int rows = 7;
for (int r = 1; r <= rows; r++) {
for (int c = 1; c <= rows; c++) {
if ((c == 1 && r == 1) ||
(c == 2 && r == 2) ||
(c == 3 && r == 3) ||
(c == 4 && r == 4) ||
(c == 5 && r == 5) ||
(c == 6 && r == 6) ||
(c == 7 && r == 7)) {
System.out.print("*");
} else {
System.out.print("0");
}
}
System.out.println();
}
}
}
Output:
*000000
0*00000
00*0000
000*000
0000*00
00000*0
000000*
BUILD SUCCESSFUL (total time: 0 seconds)
No comments:
Post a Comment