gpt-4o-2024-08-06· OpenAI
WildChat-4.8M (AI2)
Learn to write nested loops. Assignment: Given an int variable n, write a program that…
- User
Learn to write nested loops. Assignment: Given an int variable n, write a program that takes in n as user input. It then prints out an inverted triangle of integers, n rows high. Each line consists of the corresponding integers, starting at 1. You must use nested for loops to solve this question. For instance, if n is set to 4, the output of your code should be: 1 22 333 4444 . write in java and do not use any public class. with no comments, keep it short and concise.
- Assistantjava
import java.util.Scanner; class InvertedTriangle { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); for (int i = 1; i <= n; i++) { for (int j = 0; j < i; j++) { System.out.print(i); } System.out.println(); } } }