0
public class Numberpyramid {

    public static void main(String[] args) {
       int x = 9;



       for (int i =1; i<=x; i++){
       for (int j =1; j<=x-i; j++) {
               System.out.print("  ");
           }
       for (int k=i; k>=1; k--) {
               System.out.print((k>=10)?+k:" "+k);
           }
       for(int k=2; k<=i; k++) {
               System.out.print((k>=10)?+k:" "+k);
           }
       System.out.println(" ");







       }
    }
}

what can i do if i want the output to be like this

                                   1
                                 1 2 1 
                               1 2 3 2 1   
                             1 2 3 4 3 2 1
                           1 2 3 4 5 4 3 2 1
                         1 2 3 4 5 6 5 4 3 2 1
                       1 2 3 4 5 6 7 6 5 4 3 2 1
                     1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
                   1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1
2
Contributors
1
Reply
23
Views
4 Years
Discussion Span
Last Post by gusano79
0

Look at the desired output; count the number of extra spaces used to indent each line. Do you see a relationship between the number of spaces and the value of x?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.