PDA

View Full Version : equalsIgnorCase / Java




larswik
Sep 30, 2006, 02:20 AM
This code works when I have 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 while (input.equalsIgnorCase("Y"))

Here is the full 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
Sep 30, 2006, 02:30 AM
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
Sep 30, 2006, 02:34 AM
I did what you said and typed in 'equalsIgnorCase' in to Spot light and it came up with nothing.

-Lars

HiRez
Sep 30, 2006, 03:46 AM
gnasher was trying to tell you in a roundabout way that it's spelled wrong. ;)

larswik
Sep 30, 2006, 03:54 AM
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
Sep 30, 2006, 04:52 AM
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. :)