Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com;
- import java.util.Scanner;
- public class PrintTriangle2
- {
- public static void main(String[] args)
- {
- Scanner scanner = new Scanner(System.in);
- int size;
- String input;
- //check input is positive number
- do{
- while (!scanner.hasNextInt()) {
- scanner.nextLine();
- }
- input = scanner.nextLine();
- size = Integer.parseInt(input);
- }while(size <= 0);
- int count = size;
- int spaces = 0 ;
- for (int i = 0; i <size ; i++) {
- for (int j = 0; j <spaces ; j++) {
- System.out.print(" ");
- }
- for (int j = 0; j <count ; j++) {
- System.out.print("# ");
- }
- count--;
- spaces++;
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement