if else statements
Posted on 2013-12-06
In the following code:
public class play
public static void main (String args)
Scanner scan = new Scanner(System.in) ;
int apple = scan.nextInt() ;
if (apple == 1)
System.out.println("there is only 1 apple left.");
if (apple ==100)
System.out.println("there is plenty of apples here.");
If I type 1 into the scanner it prints out the statement for 1st if AND the statement for else.
If I type 100 into scanner it prints out the statement for 2nd if like it should.
If I type 2 (for example) into the scanner it prints out the else statement alone, as it should.
I don't understand why this is happening and how to print out only the 1st if statement.
I've played around with brackets and still couldn't figure it out.