Q) Write a Program to print STAR Pattern.
*
**
***
****
*****
Sol)
class Stars {
public static void main(String[] args) {
int row, numberOfStars;
for (row = 1; row <= 5; row++) {
for(numberOfStars = 1; numberOfStars <= row; numberOfStars++) {
System.out.print("*");
}
System.out.println(); // Go to next line
}
}
}
*
**
***
****
*****
Sol)
class Stars {
public static void main(String[] args) {
int row, numberOfStars;
for (row = 1; row <= 5; row++) {
for(numberOfStars = 1; numberOfStars <= row; numberOfStars++) {
System.out.print("*");
}
System.out.println(); // Go to next line
}
}
}
No comments:
Post a Comment