This lab is designed to give you more practice working with loop statements, and
ID: 3583888 • Letter: T
Question
This lab is designed to give you more practice working with loop statements, and in particular, nested loops. Getting Started To start this exercise, you should Open eclipse and start a new Java project named Lab07 Add a Class (named Lab07) to this project. For this exercise you will be creating a small Java class that will use a user validation loop to get a number in the range of 1 to 9, inclusive. Then the program will generate a triangular shaped figure on the screen, based on the user's input. The triangular shaped figure for an input of 1 is: 11 The triangular shaped figure for an input of 2 is: 11 2112 The triangular shaped figure for an input of 3 is: 11 2112 321123 The triangular shaped figure for an input of n is: 11 2112 321123 n ... 11 ... n Once you have written your class: Make sure that your programs compile and run without errors or warnings. Run your program enough times to check all the choices for correctness. If it runs correctly, then see your TA for a check-off.Explanation / Answer
class HelloWorld
{
public static void main(String arr[])
{
int row=1;
Scanner in = new Scanner(System.in);
System.out.println("Enter number of rows");
row = in.nextInt();
for(int i=1;i<=row;i++)
{
int k=1;
for(int j=1;j<=i;j++)
System.out.print(j);
System.out.println();
for(int j=i;j>=1;j--)
System.out.print(j+1);
}
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.