Results 1 to 7 of 7
Thread: While loop validation problem
- 10-08-2010, 03:08 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 4
- Rep Power
- 0
While loop validation problem
jGrasp is telling me that || can't be used in a while loop with a char type.Java Code:while (Character.toUpperCase(choice) != 'N' || != 'R') { System.out.println("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++"); System.out.println("\tPlease select 'R' or 'N' to continue "); System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); System.out.println("\tEnter 'N' for New Install or 'R' for Repair <N/R>: "); c = input.nextLine(); choice = c.charAt(0); }
so how would i use a while loop to validate 'r' 'R' 'n' 'N' only else error?
please help, thought that the || "or" would do the trick
- 10-08-2010, 03:09 AM #2
(a == b || == c) is invalid syntax. Same with != and whatnot as well. You have to do (a == b || a == c).
- 10-08-2010, 03:15 AM #3
Member
- Join Date
- Oct 2010
- Posts
- 4
- Rep Power
- 0
well i tried that, so
but its still not recognizing the r or n in lower case, and keeps looping the error.Java Code:(Character.toUpperCase(choice) != 'N' || Character.toUpperCase(choice) != 'R')
Last edited by lbatta; 10-08-2010 at 03:47 AM.
- 10-08-2010, 03:26 AM #4
Try debugging the code by printing out the value of choice to be sure of its value before the while statement tests it.its still not recognizing the r or n in lower case, and keeps looping the
error.
- 10-08-2010, 03:34 AM #5
Member
- Join Date
- Oct 2010
- Posts
- 4
- Rep Power
- 0
if i do that it prints whatever is typed, as choice = c.charAt(0) (first character typed) and c = keyboard input
- 10-08-2010, 03:41 AM #6
Member
- Join Date
- Oct 2010
- Posts
- 4
- Rep Power
- 0
omg, lol i needed && not || becase it has to not equal R "AND" N not R "OR" N
that would make it cancel each other out.
figured it out lol
- 10-08-2010, 03:49 AM #7
Agh, I should have caught that. NOT AND NOT, EQUAL OR EQUAL. Simple rule to follow, and I forgot it.
Gahhhhh... long day.......
Glad you got it working!
Similar Threads
-
While loop problem
By mochibon in forum New To JavaReplies: 3Last Post: 04-18-2010, 08:21 PM -
validation problem
By rakesh_n_mehta in forum Web FrameworksReplies: 3Last Post: 02-22-2010, 10:09 AM -
Problem with the while loop
By molokomesto in forum New To JavaReplies: 4Last Post: 02-14-2010, 05:01 PM -
simple line problem / for loop problem
By helpisontheway in forum New To JavaReplies: 1Last Post: 11-17-2009, 06:12 AM -
validation problem in list box
By rakesh_n_mehta in forum Web FrameworksReplies: 0Last Post: 10-14-2008, 07:47 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks