Results 1 to 7 of 7
  1. #1
    lbatta is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default While loop validation problem

    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);
    				
    				
    }
    jGrasp is telling me that || can't be used in a while loop with a char type.

    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

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    (a == b || == c) is invalid syntax. Same with != and whatnot as well. You have to do (a == b || a == c).

  3. #3
    lbatta is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default

    well i tried that, so

    Java Code:
    (Character.toUpperCase(choice) != 'N' || Character.toUpperCase(choice) != 'R')
    but its still not recognizing the r or n in lower case, and keeps looping the error.
    Last edited by lbatta; 10-08-2010 at 04:47 AM.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,618
    Rep Power
    25

    Default

    its still not recognizing the r or n in lower case, and keeps looping the
    error.
    Try debugging the code by printing out the value of choice to be sure of its value before the while statement tests it.

  5. #5
    lbatta is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default

    if i do that it prints whatever is typed, as choice = c.charAt(0) (first character typed) and c = keyboard input

  6. #6
    lbatta is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default

    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

  7. #7
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    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

  1. While loop problem
    By mochibon in forum New To Java
    Replies: 3
    Last Post: 04-18-2010, 09:21 PM
  2. validation problem
    By rakesh_n_mehta in forum Web Frameworks
    Replies: 3
    Last Post: 02-22-2010, 11:09 AM
  3. Problem with the while loop
    By molokomesto in forum New To Java
    Replies: 4
    Last Post: 02-14-2010, 06:01 PM
  4. simple line problem / for loop problem
    By helpisontheway in forum New To Java
    Replies: 1
    Last Post: 11-17-2009, 07:12 AM
  5. validation problem in list box
    By rakesh_n_mehta in forum Web Frameworks
    Replies: 0
    Last Post: 10-14-2008, 08:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •