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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started