Advertisement
hpilo

Chapter4_Loops_Ex13

Dec 15th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. import java.util.Scanner;
  2. /*
  3.     =====================================================
  4.                    chapter 4: Loops
  5.  
  6.                     Ex13: sand clock
  7.     =====================================================
  8. */
  9.  
  10. public class MyProgram {
  11.     public static void main(String[] args) {
  12.        
  13.         //variables
  14.         int base;
  15.         Scanner s=new Scanner(System.in);
  16.        
  17.         //user input
  18.         System.out.println("Enter triangle base: ");
  19.         base=s.nextInt();
  20.  
  21.         //printing triangle base in top
  22.         for(int i=0;i<base;i++){
  23.             for(int space=base-i;space<base;space++)    //loop for space
  24.                 System.out.print(" ");
  25.             for(int j=i;j<base;j++)
  26.                 System.out.print("* ");     //loop for stars
  27.             System.out.println();
  28.         }
  29.  
  30.         //printing triangle base in bottom
  31.         for(int i=0;i<base;i++) {
  32.             for (int space = i+1; space < base; space++)    //loop for space
  33.                 System.out.print(" ");
  34.             for (int j = base-i-1; j < base; j++)
  35.                 System.out.print("* ");     //loop for stars
  36.             System.out.println();
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement