Problem: Triangle - Left Justified
Draw right angled triangle of given height
Sample input:
5
Sample output
12345
5
Sample output
12345
1234
123
12
1
Solve:
Lets see the following code:
// ADLabs import java.util.Scanner; public class NastedForLoop { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter any Int Num:"); int n = sc.nextInt(); System.out.println(); // Triangle - Left Justified - up side down for (int i = n; i >= 1; i--) { for (int j = 1; j <= i; j++) { System.out.print(j); } System.out.println(); } sc.close(); } }
Console:
Enter any Int Num:5
12345
1234
123
12
1
Happy Coding :)
-@D
Enter any Int Num:5
12345
1234
123
12
1
Happy Coding :)
-@D