165k views
5 votes
The following code is intended to test whether the int variable num is less than 10, and if so print a warning and set it to 10. The code then prints the value of num.

if (num < 10)
System.out.println( "This is smaller than 10" );
num = 10;
System.out.println("Value of num is " + num);
What correction should be made so the code functions as intended?

An else statement should be added between the 3rd and 4th lines
The final line should be printed every time, not just when num hasn’t been changed.
A semicolon should be added at the end of the first line
The operator ‘<’ should be changed to ‘<=’ in the if statement
No correction should be made
Curly braces ‘{ }‘ should be added to enclose the second and third lines

The following code is intended to test whether the int variable num is less than 10, and-example-1
User Gil G
by
5.3k points

2 Answers

2 votes

The right answer are: Curly braces ‘{ }‘ should be added to enclose the second and third lines

Step-by-step explanation:

Because the last line always needs to be print out so the “{ }” will make the second and third line only print when conditions meet the if condition.

User Eppz
by
5.1k points
4 votes

The only correction I see is you need to add curly braces to enclose the second and third lines.

User Altons
by
4.3k points