181k views
4 votes
Which of the following if statements correctly executes all three following commands only when the if condition is true?I.if ( x < 10) int ans; ans = x * 90; System.out.println( "answer: " + ans);II.if ( x < 10){ int ans; ans = x * 90; System.out.println( "answer: " + ans); }III.if { ( x < 10) int ans; ans = x * 90; System.out.println( "answer: " + ans);}

II only
I, II and III
I only
I and III
III only

User Leom Burke
by
4.8k points

1 Answer

1 vote

Answer:

II only.

Step-by-step explanation:

The block that you want executed if the if-expression (x<10) is true, has to be enclosed in { ... }.

I is wrong because it only declares "ans" conditionally. It wouldn't compile even.

II is correct.

III has the opening curly brace at the wrong place. It will not compile.

User GlaIZier
by
4.4k points