Mac equalsIgnorCase / Java

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
This code works when I have
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
 

gnasher729

macrumors P6
Nov 25, 2005
16,532
3,131
Use spotlight (command space) and type in equalsIgnorCase. Count how many results you get. Then type equalsIgnoreCase and count the result. Draw your own conclusions.
 

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
I did what you said and typed in 'equalsIgnorCase' in to Spot light and it came up with nothing.

-Lars
 

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
I'm sorry, I guess I was that lame. When I typed it with a E it worked fine.

I'm learning : (

Thanks for the help and sorry again that was a stupid move

-Lars
 

Kunimodi

macrumors member
Sep 8, 2006
65
0
Ashland, OR, USA
larswik said:
I'm sorry, I guess I was that lame. When I typed it with a E it worked fine.

I'm learning : (

Thanks for the help and sorry again that was a stupid move

-Lars
Hey, it's really no big deal. All programmers make typos and thinkos, even the best of them. You're making a great effort and many folks here are happy to help. :)