Im trying to print a half pyramid with number and stars together and the output must be like this
1 1 1 1 1 1 1
2 * * * * 2
3 * * * 3
4 * * 4
5 * 5
6 6
7
Here is the code that ive done so far
public class numberplsustar {
public static void main(String[] args) {
int rows = 7,i,j,num;
for (i = rows; i >= 1; i--) {
for (j = 1; j <= i; ++j) {
if(i>=3 && i<=6){
System.out.print("* ");
}
else
System.out.print(i+" ");
}
System.out.println();
}
}
}
And this is the output
7 7 7 7 7 7 7
* * * * * *
* * * * *
* * * *
* * *
2 2
1
Aucun commentaire:
Enregistrer un commentaire