Didart

Printing Triangle

Oct 7th, 2021
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class PrintingTriangle {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.        int n = Integer.parseInt(scanner.nextLine());
  8.  
  9.         for (int i = 1; i <= n ; i++) {
  10.             printLine(1, i);
  11.         }
  12.  
  13.         for (int i = n - 1; i >= 1 ; i--) {
  14.             printLine(1, i);
  15.         }
  16.     }
  17.  
  18.     public static void printLine(int start, int end) {
  19.         for (int i = start; i <= end ; i++) {
  20.             System.out.print(i + " ");
  21.         }
  22.         System.out.println();
  23.     }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment