break problem

I'm having trouble finishing this program, I can't seem to figure out whats wrong with it, I keep getting an error message I don't understand. Here's my code so far:

import java.util.Scanner;

public class PickTint

{

public static void main (String[ ] args)

{

int letter, colour;

Scanner scan = new Scanner (System.in);

System.out.println ("R Red");

System.out.println ("O Orange");

System.out.println ("Y Yellow");

System.out.println ("G Green");

System.out.println ("B Blue");

System.out.print ("Choose a colour from menu above :");

letter = scan.nextInt( );

colour = letter;

System.out.print ("You chose ");

switch (colour)

{

case 'R':

System.out.println ("Red");

break;

case 'r':

System.out.println ("red");

break;

case 'O':

System.out.println ("Orange");

break;

case 'o':

System.out.println ("Orange");

break;

case 'Y':

System.out.println ("Yellow");

break;

case 'y':

System.out.println ("Yellow");

break;

case 'G':

System.out.println ("Green");

break;

case 'g':

System.out.println ("Green");

break;

case 'B':

System.out.println ("Blue");

break;

case 'b':

System.out.println ("Blue");

break;

default:

System.out.println ("a non-existent item");

}

}

}

Any advice?

[1521 byte] By [tool_fana] at [2007-11-26 21:45:19]
# 1

> Any advice?

yep

1) post using [code] tags

2) if you have an error, whether you understand it or not, post it here. my psychic powers don't work on Thursdays, I don't know about anyone elses

3) try and not guess what the problem might be (break problem) - tell us what's actually going wrong

4) watch the Bikini Bandits movie. you'll never listen to tool the same way again :-)

georgemca at 2007-7-10 3:33:58 > top of Java-index,Java Essentials,New To Java...
# 2

> > Any advice?

>

> yep

>

> 1) post using [code] tags

> 2) if you have an error, whether you understand it or

> not, post it here. my psychic powers don't work on

> Thursdays, I don't know about anyone elses

> 3) try and not guess what the problem might be (break

> problem) - tell us what's actually going wrong

> 4) watch the Bikini Bandits movie. you'll never

> listen to tool the same way again :-)

okay, lets try again....

import java.util.Scanner;

public class PickTint

{

public static void main (String[ ] args)

{

int letter, colour;

Scanner scan = new Scanner (System.in);

System.out.println ("R Red");

System.out.println ("O Orange");

System.out.println ("Y Yellow");

System.out.println ("G Green");

System.out.println ("B Blue");

System.out.print ("Choose a colour from menu above :");

letter = scan.nextInt( );

colour = letter;

System.out.print ("You chose ");

switch (colour)

{

case 'R':

System.out.println ("Red");

break;

case 'r':

System.out.println ("red");

break;

case 'O':

System.out.println ("Orange");

break;

case 'o':

System.out.println ("Orange");

break;

case 'Y':

System.out.println ("Yellow");

break;

case 'y':

System.out.println ("Yellow");

break;

case 'G':

System.out.println ("Green");

break;

case 'g':

System.out.println ("Green");

break;

case 'B':

System.out.println ("Blue");

break;

case 'b':

System.out.println ("Blue");

break;

default:

System.out.println ("a non-existent item");

}

}

}

tool_fana at 2007-7-10 3:33:58 > top of Java-index,Java Essentials,New To Java...
# 3
if georgemc is a tool fan then my whole concept of reality has been blown apart, lol. (--> fan since '93)
TuringPesta at 2007-7-10 3:33:58 > top of Java-index,Java Essentials,New To Java...
# 4
the error is:at java.util.Scanner.next(Scanner.java:1431)at java.util.Scanner.nextInt(Scanner.java:2040)at java.util.Scanner.nextInt(Scanner.java:2000)at PickTint.main(PickTint.java:27)i think
tool_fana at 2007-7-10 3:33:58 > top of Java-index,Java Essentials,New To Java...
# 5

> > > Any advice?

> >

> > yep

> >

> > 1) post using [code] tags

> > 2) if you have an error, whether you understand it

> or

> > not, post it here. my psychic powers don't work on

> > Thursdays, I don't know about anyone elses

> > 3) try and not guess what the problem might be

> (break

> > problem) - tell us what's actually going wrong

> > 4) watch the Bikini Bandits movie. you'll never

> > listen to tool the same way again :-)

>

> okay, lets try again....

> > import java.util.Scanner;

>

> public class PickTint

> {

> public static void main (String[ ] args)

>

> {

> int letter, colour;

>

> Scanner scan = new Scanner (System.in);

>

> System.out.println ("R Red");

> System.out.println ("O Orange");

> System.out.println ("Y Yellow");

> System.out.println ("G Green");

> System.out.println ("B Blue");

>

> System.out.print ("Choose a colour from menu above

> :");

> letter = scan.nextInt( );

>

> colour = letter;

>

> System.out.print ("You chose ");

>

> switch (colour)

> {

> case 'R':

> System.out.println ("Red");

> break;

>

> case 'r':

> System.out.println ("red");

> break;

>

> case 'O':

> System.out.println ("Orange");

> break;

>

> case 'o':

> System.out.println ("Orange");

> break;

>

> case 'Y':

> System.out.println ("Yellow");

> break;

>

> case 'y':

> System.out.println ("Yellow");

> break;

>

> case 'G':

> System.out.println ("Green");

> break;

>

> case 'g':

> System.out.println ("Green");

> break;

>

> case 'B':

> System.out.println ("Blue");

> break;

>

> case 'b':

> System.out.println ("Blue");

> break;

>

> default:

> System.out.println ("a non-existent item");

> }

>

> }

> }

>

slightly better. now, what's this error you're on about?

georgemca at 2007-7-10 3:33:58 > top of Java-index,Java Essentials,New To Java...
# 6

> the error is:

> at java.util.Scanner.next(Scanner.java:1431)

> at java.util.Scanner.nextInt(Scanner.java:2040)

> at java.util.Scanner.nextInt(Scanner.java:2000)

> at PickTint.main(PickTint.java:27)

>

> i think

it's not. thats part of a stack trace, and not much use on its own. post the entire thing

georgemca at 2007-7-10 3:33:58 > top of Java-index,Java Essentials,New To Java...
# 7
> if georgemc is a tool fan then my whole concept of> reality has been > blown apart, lol. (--> fan since '93)Saw them in November, unreal.
tool_fana at 2007-7-10 3:33:58 > top of Java-index,Java Essentials,New To Java...
# 8
Great :)Who else wants code tags? :)
Michael.Nazarov@sun.coma at 2007-7-10 3:33:58 > top of Java-index,Java Essentials,New To Java...
# 9

> if georgemc is a tool fan then my whole concept of

> reality has been

> blown apart, lol. (--> fan since '93)

not a fan, per se, but I like 'em. not really heavy enough for me, though. APC seemed better live, too

why would that blow your concept of reality apart, anyway?

georgemca at 2007-7-10 3:33:58 > top of Java-index,Java Essentials,New To Java...
# 10
*ahem*Why doesn't my code work?Please help!
tool_fana at 2007-7-10 3:33:58 > top of Java-index,Java Essentials,New To Java...
# 11
> *ahem*> > Why doesn't my code work?> Please help!You still haven't given us the error. Post the entire stack trace please.
hunter9000a at 2007-7-10 3:33:58 > top of Java-index,Java Essentials,New To Java...
# 12
> *ahem*> > Why doesn't my code work?> Please help!erm, post whole stack trace? btw, why do you bother re-assigning "letter" to "colour"? seems pointless to me
georgemca at 2007-7-10 3:33:58 > top of Java-index,Java Essentials,New To Java...
# 13

I get this:

java.util.InputMismatchException

at java.util.Scanner.throwFor(Scanner.java:819)

at java.util.Scanner.next(Scanner.java:1431)

at java.util.Scanner.nextInt(Scanner.java:2040)

at java.util.Scanner.nextInt(Scanner.java:2000)

at PickTint.main(PickTint.java:27)

tool_fana at 2007-7-10 3:33:58 > top of Java-index,Java Essentials,New To Java...
# 14
> java.util.InputMismatchExceptionOh yeah! This is "break problem" and should remove all break statements to avoid it...
Michael.Nazarov@sun.coma at 2007-7-10 3:33:58 > top of Java-index,Java Essentials,New To Java...
# 15
> > java.util.InputMismatchException> > Oh yeah! This is "break problem" and should remove> all break statements to avoid it...No no, it means he needs to add more breaks. :)
hunter9000a at 2007-7-21 18:25:40 > top of Java-index,Java Essentials,New To Java...
# 16
sorry, not sure why i said it was a break problem :?But can anyone give me advice to why this doesn't work? Please.
tool_fana at 2007-7-21 18:25:40 > top of Java-index,Java Essentials,New To Java...
# 17

> sorry, not sure why i said it was a break problem :?

Even you not sure? Terrible...

> But can anyone give me advice to why this doesn't work? Please.

Read your error text and think. "InputMismatchException" means there is problem with your input. Think again - what did you input and what are you want to be inputted?

Michael.Nazarov@sun.coma at 2007-7-21 18:25:40 > top of Java-index,Java Essentials,New To Java...
# 18
> sorry, not sure why i said it was a break problem> :?> > But can anyone give me advice to why this doesn't> work? Please.you're calling nextInt, but inputting characters
georgemca at 2007-7-21 18:25:40 > top of Java-index,Java Essentials,New To Java...
# 19
I'm sorry but I'm still having problems with this. I hate to ask someone to spell it out for me, but I'm just getting to frustrated.Yours faithfully, a noob.
tool_fana at 2007-7-21 18:25:40 > top of Java-index,Java Essentials,New To Java...
# 20
Scrapped. Misread.Message was edited by: kikemelly
kikemellya at 2007-7-21 18:25:40 > top of Java-index,Java Essentials,New To Java...
# 21

so I've changed it to this:

import java.util.Scanner;

public class Palindrone

{

public static void main (String[ ] args)

{

char colour;

int letter;

Scanner sc = new Scanner (System.in);

System.out.println ("R Red");

System.out.println ("O Orange");

System.out.println ("Y Yellow");

System.out.println ("G Green");

System.out.println ("B Blue");

System.out.print ("Choose a colour from menu above :");

char ch = sc.next() .charAt(0);

System.out.print ("You chose " + ch);

colour = letter;

switch (colour)

{

case 'R':

System.out.println ("Red");

break;

case 'r':

System.out.println ("red");

break;

case 'O':

System.out.println ("Orange");

break;

case 'o':

System.out.println ("Orange");

break;

case 'Y':

System.out.println ("Yellow");

break;

case 'y':

System.out.println ("Yellow");

break;

case 'G':

System.out.println ("Green");

break;

case 'g':

System.out.println ("Green");

break;

case 'B':

System.out.println ("Blue");

break;

case 'b':

System.out.println ("Blue");

break;

default:

System.out.println ("a non-existent item");

}

}

}

but it's still not happening. Where am I going wrong?

tool_fana at 2007-7-21 18:25:40 > top of Java-index,Java Essentials,New To Java...