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]

> 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 :-)
> > 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");
}
}
}
if georgemc is a tool fan then my whole concept of reality has been blown apart, lol. (--> fan since '93)
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
> > > 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?
> 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
> 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.
Great :)Who else wants code tags? :)
> 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?
*ahem*Why doesn't my code work?Please help!
> *ahem*> > Why doesn't my code work?> Please help!You still haven't given us the error. Post the entire stack trace please.
> *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
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)
> java.util.InputMismatchExceptionOh yeah! This is "break problem" and should remove all break statements to avoid it...
> > 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. :)
sorry, not sure why i said it was a break problem :?But can anyone give me advice to why this doesn't work? Please.
> 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?
> 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
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.
Scrapped. Misread.Message was edited by: kikemelly
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?
