Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. import javax.swing.*;
  2.  
  3. public class Assignment {
  4.    
  5.     public Assignment() {
  6.    
  7.     int pyramidLines = 7;
  8.     String output = "";
  9.     int toAdd = 0;
  10.    
  11.    
  12.     for(int i = pyramidLines; i >= 0; i--) {
  13.        
  14.         int num = 1;
  15.        
  16.         for(int j = 0; j <= (i + toAdd); j++) {
  17.        
  18.         if(j < i)
  19.             output += " ";
  20.         else if (j < i + (toAdd / 2)) {
  21.             output += Integer.toString(num);
  22.             num = num * 2;
  23.         }
  24.         else {
  25.             output += Integer.toString(num);
  26.             num = num / 2;
  27.         }
  28.        
  29.         }
  30.        
  31.         System.out.println(output);
  32.         output = "";
  33.         toAdd += 2;
  34.     }
  35.     }
  36.    
  37.     public static void main(String[] args) {
  38.     new Assignment();
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement