Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class TriangleOfNumbers {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = scanner.nextInt();
- int count =1;
- for (int i = 1; i <= n; i++) { // number of rows
- for (int j = 1; j <= i; j++) { // cols
- System.out.printf("%d ", count);
- }
- count++;
- System.out.println(" "); // to form the triangle, otherwise they are printed in a single row
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement