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

Respuesta :

tonb

Answer:

II only.

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.