Results 1 to 9 of 9
Thread: Kind of stuck
- 10-22-2010, 10:49 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 1
- Rep Power
- 0
Kind of stuck
Hey guys I have been doing an assignment first time I have used Java and I am not sure why my while statements dont seem to work? What I am trying to do is to re-ask a user a question if they enter a false answer. There are only two correct answers blue or white and if they enter purple I want it to be re-asked. Could anyone give me some help with this?
Thanks, complete newb to java I rarely ask for help when it comes to things but this is something that confuses me.Java Code:System.out.println("Please choose a colour, blue or white?"); colour = scanner.nextLine(); colour = colour.toLowerCase(); // Changes the case of the String colour to lower case rather than ignoring it if (colour.equals("white")) { System.out.println("Hello " + forename + " " + surname + ", Swansea City play in white."); } else if (colour.equals("blue")) { System.out.println("Hello " + forename + " " + surname + ", Cardiff City play in blue."); } else { System.out.println("Sorry," + forename +", I did not understand you"); } } }
- 10-22-2010, 11:08 AM #2
If you could, please post the whole thing
- 10-22-2010, 12:00 PM #3
Member
- Join Date
- Aug 2010
- Location
- Leuven, Belgium
- Posts
- 79
- Rep Power
- 0
Hi,
Instead of
tryJava Code:colour.equals("white")
GreetingsJava Code:colour.compareTo("white") == 0
-
- 10-22-2010, 12:28 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
- 10-22-2010, 12:48 PM #6
Member
- Join Date
- Aug 2010
- Location
- Leuven, Belgium
- Posts
- 79
- Rep Power
- 0
Hi,
Java Code:What is the benefit of doing this?
Because compareTo compares the text.
I am using this and it works
greetz
- 10-22-2010, 12:52 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
- 10-22-2010, 01:23 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
- 10-22-2010, 02:46 PM #9
Member
- Join Date
- Aug 2010
- Location
- Leuven, Belgium
- Posts
- 79
- Rep Power
- 0
There is not.Java Code:It may work, but how does using a method intended for ordering (compareTo) make more sense to use when looking at equality than a method (equals) that simply handles equality?
I thought that that was the question.
I have tested the code and the code is working fine.
So JosAh is correct, where is the while statement because the rest is working.
Greetz
Similar Threads
-
kind of Component being return? and Conversion
By mine0926 in forum NetBeansReplies: 11Last Post: 05-17-2010, 10:11 AM -
';' expected, not of the common kind..
By Addez in forum New To JavaReplies: 6Last Post: 09-02-2009, 04:37 AM -
how client know what kind of server
By lemur in forum NetworkingReplies: 3Last Post: 05-31-2008, 07:11 AM -
Total Newbie, Be Kind :)
By dazza-s in forum New To JavaReplies: 11Last Post: 04-26-2008, 10:54 PM -
Will make a pyramid of some kind out of a number
By romina in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:20 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks