Advertisement
Guest User

Untitled

a guest
Mar 4th, 2012
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. package com.dailyprogrammer;
  2.  
  3. import java.util.Scanner;
  4. import static java.lang.System.out;
  5.  
  6.  
  7. public class Easy17 {
  8.  
  9.     /**
  10.      * @param args
  11.      */
  12.     public static void main(String[] args) {
  13.  
  14.         Scanner s = new Scanner(System.in);
  15.         out.println("What height would you like the  triangle?");
  16.         int height = s.nextInt();
  17.        
  18.         growingTriangle(height);
  19.         shrinkingTriangle(height);
  20.        
  21.  
  22.     }
  23.    
  24.     private static void growingTriangle(int h){
  25.         for (int i=0; i<h; i++){
  26.             for(int j=1; j<=Math.pow(2, i); j++){
  27.                 out.printf("@");
  28.             }
  29.             out.println();
  30.         }
  31.     }
  32.    
  33.     private static void shrinkingTriangle(int h){
  34.         for (int i=h-1; i>=0; i--){
  35.             for(int j=1; j<=Math.pow(2, i); j++){
  36.                 out.printf("@");
  37.             }
  38.             out.println();
  39.         }
  40.     }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement