Results 1 to 2 of 2
  1. #1
    durdanto is offline Member
    Join Date
    Feb 2011
    Posts
    20
    Rep Power
    0

    Default string and condition problem

    I am trying to perform a task that checks the letter that user inputs (ignoring case) and return the desired:
    if the letter contains "System.out.print ("right")
    if not "--> Not a valid request "

    i did the following code but in either cases it returns as "--> Not a valid request "

    plz help

    Java Code:
    String letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    Scanner kb = new Scanner(System.in);
    		String guessWord = kb.next();
    //condition
    				if (guessLetter.contains(letters) ||guessLetter.toLowerCase().contains(letters))
    					System.out.println("Right ");
    				else System.out.println("--> Not a valid request " +
    						"- either not a letter or already guesses. ");

  2. #2
    Join Date
    Feb 2011
    Location
    Ahmedabad
    Posts
    36
    Rep Power
    0

    Default reply to string and condition problem

    check your condition there is a mistake in name of variables

    it should be as follow

    Java Code:
    if (letters.contains(guessWord) ||letters.toLowerCase().contains(guessWord))

Similar Threads

  1. Replies: 5
    Last Post: 06-22-2010, 09:34 AM
  2. boolean condition creating problem
    By Basit781 in forum CLDC and MIDP
    Replies: 1
    Last Post: 05-25-2010, 07:57 AM
  3. Concatinating contents of a string array based on condition
    By gangsterooseven in forum Advanced Java
    Replies: 2
    Last Post: 10-07-2009, 07:35 AM
  4. IF-Condition in a String
    By lenaz in forum Advanced Java
    Replies: 1
    Last Post: 07-18-2009, 12:07 PM
  5. problem with using string in if condition
    By sireesha in forum New To Java
    Replies: 2
    Last Post: 11-20-2007, 10:40 PM

Posting Permissions

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