62.3k views
0 votes
What the output from the following code fragment:

int t1 = 87;
int t2 = 78;
int larger;
if( t1 > t2 )
larger = t1;
else
larger = t2;
System.out.println( "larger: " + larger );

User Dexters
by
6.1k points

1 Answer

5 votes
The output will result to
Nothing because there inst curly braces inserted so this code is continuously running.
But if there was the output would result in Larger: 78 because your Sytem.out.prinln("Larger: " + larger );
Because it is located in the else statement
If you want it to print out either way you would write it like so

int t1 = 87; int t2 = 78; String larger = ""; if(t1 > t2){ larger = t1; }else{ larger = t2; } System.out.println("Larger: " + larger);
User Mikeck
by
5.8k points