Advertisement
nov0

Z4_PrintPiramid

May 30th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Z4_Piramid {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner input = new Scanner(System.in);
  7.         System.out.print("Enter number of lines: ");
  8.         int num = input.nextInt();
  9.        
  10.         piramid(num);
  11.        
  12.         input.close();
  13.     }
  14.    
  15.     public static void piramid(int n){
  16.         for(int i = 1; i <= n; i++){
  17.             for(int j = n; j > 0; j--){
  18.                 if(j <= i){
  19.                     System.out.print(j + " ");
  20.                 } else {
  21.                     System.out.print("  ");
  22.                 }
  23.             }
  24.            
  25.             for(int k = 2; k <= n; k++){
  26.                 if(k <= i){
  27.                     System.out.print(k + " ");
  28.                 } else {
  29.                     System.out.print(" ");
  30.                 }
  31.             }
  32.             System.out.println();
  33.         }
  34.  
  35.     }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement