Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Pyramid {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- int current =1;
- boolean isBigger = false;
- for (int rows = 1; rows<=n; rows++){
- for (int cols=1; cols<=rows; cols++){
- if (current > n){
- isBigger = true;
- break;
- }
- System.out.print(current + " ");
- current++;
- }
- if (isBigger){
- break;
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement