Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. public class DisplayPyramid {
  2. public static void main(String args[]) {
  3. Scanner sc = new Scanner(System.in); // Scanner class in java
  4. System.out.print("Enter the rows you want:");
  5. int rows = sc.nextInt();
  6. System.out.println("");
  7. for (int i = 1; i <= rows; i++) {// outer forloop
  8. for (int j = 1; j <= (rows - i) * 2; j++) {
  9. System.out.print(" ");// create initial space for pyramid shape
  10. }
  11. for (int k = i; k >= 1; k--) {// inner for loops
  12. System.out.print(" " + k);// create left half
  13. }
  14. for (int l = 2; l <= i; l++) {
  15. System.out.print(" " + l); // create right half
  16. } // end outer for loop
  17. System.out.println();
  18. }
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement