Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Easy17 {
- public static void main(String[] args) {
- // get input
- Scanner s = new Scanner(System.in);
- System.out.print(" Triangle creator\n--------------------\nEnter a height: ");
- int height = s.nextInt();
- System.out.print("Reversed? (true/false) : ");
- boolean reverse = (s.nextBoolean());
- System.out.print("Right justified? (true/false) : ");
- boolean rjust = (s.nextBoolean());
- if (!reverse) {
- // output triangle regularly
- int length = 1;
- for (int i=0;i<height;i++) {
- if (rjust) for (int j=0;j<Math.pow(2,height-1)-length;j++) System.out.print(" ");
- for (int j=0;j<length;j++) System.out.print("@");
- length *= 2;
- System.out.println();
- }
- } else {
- // output triangle in reverse
- int length = (int)Math.pow(2, height-1);
- for (int i=0;i<height;i++) {
- if (rjust) for (int j=0;j<Math.pow(2,height-1)-length;j++) System.out.print(" ");
- for (int j=0;j<length;j++) System.out.print("@");
- length /= 2;
- System.out.println();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement