hpilo

Chapter4_Loops_Ex11

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