97.5k views
3 votes
What is printed out by the following code fragment?

int n = 15;
A) if ( 10 <= n && 20 <= n ) { System.out.println( "A" ); } else { System.out.println( "B" ); }
B) if ( 10 < n || 20 < n ) { System.out.println( "C" ); } else { System.out.println( "D" ); }
C) if ( n != 15 ) { System.out.println( "E" ); } else { System.out.println( "F" ); }
D) if ( n == 15 ) { System.out.println( "G" ); } else {
E) if ( n > 0 ) { System.out.println( "H" ); } }

User Lexi
by
8.7k points

1 Answer

2 votes

Answer:

The following code will return the Output is:

B

C

F

G

Explanation:

A.) In the first option, n is greater than 10 and n is less than 20.

so, the condition of the if statement goes false and else will be executed and it print B.

B.) In the second option, n is greater than 10 or n is less than 20.

so, the condition of the if goes true and else part will not be executed and it print C.

C.) In the third statement, n is equal to the 15.

so, the condition of the if statement goes false and else part will be executed and it print F.

D.) & F.) In the last two statements, n is equal to the 15.

so, the condition of D option goes true and else part of option E will not be executed and it prints G.

User Alessandro Ornano
by
8.1k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.

9.4m questions

12.2m answers

Categories