SHARE
TWEET

Untitled

a guest May 19th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top