Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /*
- =====================================================
- chapter 4: Loops
- Ex11: printing square: bottom triangle * | top triangle #
- =====================================================
- */
- public class MyProgram {
- public static void main(String[] args) {
- //variables
- int size;
- Scanner s=new Scanner(System.in);
- //user input
- System.out.println("Enter square size: ");
- size=s.nextInt();
- //printing square
- for(int i=0;i<size;i++){
- for(int j=size-i-1;j<size;j++) { // bottom triangle *
- System.out.print(" * ");
- }
- for(int k=i+1;k<size;k++) //top triangle #
- System.out.print(" # ");
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment