PDA

View Full Version : compiler wont run and i need a lil help


Uber Fr0g
02-14-2006, 04:02 AM
hey, im having a little trouble with my compiler and need a little help determining the output of a program. I need to determine the output for the following code sets when x is 9 and y is 11, and when x is 11 and y is 9. I tried to figure it out on paper but im new to java and struggling a bit.

heres the code:


if (x < 10 )
if (y > 10)
System.out.println( "*****" );
else
System.out.println( "#####" );
System.out.println( "$$$$$");




if (x < 10 )
{
if (y > 10)
System.out.println( "*****" );
}
else
{
System.out.println( "#####" );
System.out.println( "$$$$$");
}

_Aerospace_Eng_
02-14-2006, 06:11 AM
For the first code

x=9, y=11
x=11, y=9
Output 1: x=9, y=11
*****
$$$$$

Output 2: x=11, y=9
$$$$$$

For the second code

Output 1: x=9, y=11
*****

Output 2: x=11, y=9
#####
$$$$$

I'm guessing you are trying to see what if statements will be read. If no brackets are used then the next executable statement after the if or else will be the only line that is read.