Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- public class Assignment {
- public Assignment() {
- int pyramidLines = 7;
- String output = "";
- int toAdd = 0;
- for(int i = pyramidLines; i >= 0; i--) {
- int num = 1;
- for(int j = 0; j <= (i + toAdd); j++) {
- if(j < i)
- output += " ";
- else if (j < i + (toAdd / 2)) {
- output += Integer.toString(num);
- num = num * 2;
- }
- else {
- output += Integer.toString(num);
- num = num / 2;
- }
- }
- System.out.println(output);
- output = "";
- toAdd += 2;
- }
- }
- public static void main(String[] args) {
- new Assignment();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement