equalsIgnorCase / Java

Discussion in 'Mac Programming' started by larswik, Sep 29, 2006.

  1. larswik macrumors 68000

    Joined:
    Sep 8, 2006
    #1
    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
     
  2. gnasher729 macrumors Pentium

    gnasher729

    Joined:
    Nov 25, 2005
    #2
    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.
     
  3. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #3
    I did what you said and typed in 'equalsIgnorCase' in to Spot light and it came up with nothing.

    -Lars
     
  4. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #4
    gnasher was trying to tell you in a roundabout way that it's spelled wrong. ;)
     
  5. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #5
    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
     
  6. Kunimodi macrumors member

    Joined:
    Sep 8, 2006
    Location:
    Ashland, OR, USA
    #6
    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. :)
     

Share This Page