Question: The if statement is used to implement a decision. The simplest form of an if statement has two parts: a condition and a body. If

The if statement is used to implement a decision. The simplest form of an if statement has two parts: a condition and a body. If the condition is true, the body of the statement is executed. The body of the if statement consists of a statement block.

Create an Eclipse project named Lab_Project_10. Add a Main class (with a main method) to your project.

Then, copy the hightlighted code below to your main method:

import java.util.Scanner;

public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int n; System.out.print("Enter n: "); n = cin.nextInt(); if (n > 10) { System.out.print("*****"); } if (n > 7) { System.out.print("****"); } if (n > 4) { System.out.print("***"); } if (n > 1) { System.out.print("**"); } System.out.println("*"); } // end main } // end class Main

How many *s will be printed when the code is executed

a) with n = 6? b) with n = 20? c) with n = 2? d) with n = 1?

Why? Provide a trace of the code (i.e., a description of the executed statements) for each answer.

Type your answers in the space provided below, and Submit your answers.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!