I would like the output to have 9 spaces then a star, 8 spaces then two stars, 7 spaces and 3 stars and so on until 10 stars at the bottom. How can I generate the spaces?
import java.util.Scanner;
public class ThreeDotTwelvea
{
public static void main(String args[])
{
final int max_rows = 1;
for (int row = 10; row >= max_rows; row--)
{
for (int star = 1; star <= row; star++)
System.out.print ("*");
System.out.println();
}
}
}
try this
public class ThreeDotTwelvea {
final static int NO_OF_ROWS = 10;
public static void main(String[] args) {
for (int i = 0; i < NO_OF_ROWS; i++) {
for (int j = NO_OF_ROWS - i - 1; j > 0; j--) {
System.out.print(" ");
}
for (int j = 0; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
OUTPUT
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.