This code works when I have
The book that I am reading from uses it this way but that doesn't work and I get an error
Here is the full code
I have reviewd it many times and it looks like I wrote it the way it is on the book. This is code that I wrote from examples in the book but it should work weather it is 'equals or equalsIgnorCase'. It runs with the 'equals' but if I use a small case 'y' it quits out.
I'm guessing it might be the version of JAVA that I have installed. 1.4.2 which was the lateset on the Developer Tools from the Apple site. Or is my code for that part wrong?
thanks
lars
Code:
while (input.equals("Y"))
The book that I am reading from uses it this way but that doesn't work and I get an error
Code:
while (input.equalsIgnorCase("Y"))
Here is the full code
Code:
import java.util.Scanner;
public class apples
{
static Scanner i = new Scanner(System.in);
public static void main(String [] args)
{
String input = "Y";
while (input.equalsIgnorCase("Y"))
{
System.out.print("A Number Please ");
int ac = i.nextInt();
if (ac == 0)
System.out.println("You didn't make a selection.");
if (ac == 1)
System.out.println("You have " + ac + " apple!");
if (ac > 1)
System.out.println("You have " + ac + " apples!");
System.out.print("Keep Playing? " + "Y or N: ");
input = i.next();
}
}
}
I have reviewd it many times and it looks like I wrote it the way it is on the book. This is code that I wrote from examples in the book but it should work weather it is 'equals or equalsIgnorCase'. It runs with the 'equals' but if I use a small case 'y' it quits out.
I'm guessing it might be the version of JAVA that I have installed. 1.4.2 which was the lateset on the Developer Tools from the Apple site. Or is my code for that part wrong?
thanks
lars