Advertisement
alvsjo

Piramide brojeva

Dec 10th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class piramidbroj {
  5.  
  6.     public static void main(String[] args) {
  7.         // TODO Auto-generated method stub
  8.  
  9.         Scanner input = new Scanner (System.in);
  10.         int n=input.nextInt();
  11.        
  12.         for(int i=1;i<=n;i++)
  13.         {
  14.            
  15.             for(int p=1;p<=i;p++)
  16.                 System.out.print(p);
  17.            
  18.             System.out.println();
  19.            
  20.         }
  21.        
  22.         System.out.println(); System.out.println();
  23.        
  24.         for(int i=1;i<=n;i++)
  25.         {
  26.             for(int k=n-i;k>0;k--)
  27.                 System.out.print(" ");
  28.            
  29.             for(int p=1;p<=i;p++)
  30.                 System.out.print(p);
  31.            
  32.             System.out.println();
  33.            
  34.         }
  35.        
  36.        
  37.         System.out.println();System.out.println();
  38.        
  39.         for(int i=1;i<=n;i++)
  40.         {
  41.             for(int k=n-i;k>0;k--)
  42.                 System.out.print(" ");
  43.            
  44.             for(int p=1;p<=i;p++)
  45.                 System.out.print(p);
  46.             for(int p=i-1;p>=1;p--)
  47.                 System.out.print(p);
  48.            
  49.             System.out.println();
  50.            
  51.         }
  52.        
  53.        
  54.        
  55.     }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement