Advertisement
Guest User

Untitled

a guest
May 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TriangleOfNumbers {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int n = scanner.nextInt();
  8. int count =1;
  9.  
  10. for (int i = 1; i <= n; i++) { // number of rows
  11. for (int j = 1; j <= i; j++) { // cols
  12.  
  13. System.out.printf("%d ", count);
  14.  
  15. }
  16. count++;
  17. System.out.println(" "); // to form the triangle, otherwise they are printed in a single row
  18.  
  19. }
  20.  
  21.  
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement