TheBulgarianWolf

Triangle of numbers

Apr 10th, 2020
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.44 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SoftUni {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.         System.out.print("Enter a number: ");
  8.         int n = Integer.parseInt(sc.nextLine());
  9.  
  10.         for (int i = 0; i < n; i++) {
  11.             for (int k = 1; k <= i + 1; k++) {
  12.                 System.out.print(i + 1 + " ");
  13.             }
  14.             System.out.println();
  15.         }
  16.     }
  17.  
  18. }
Add Comment
Please, Sign In to add comment