Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Using string class (https://www.askmehelpdesk.com/showthread.php?t=140259)

  • Oct 13, 2007, 01:06 PM
    albear
    using string class
    I'm not entirely sure what I'm doing wrong but I think whatever it is, is part of my 'is' statement, I'm trying to get the program to tell if user input is valid or not.

    import java.util.*; // the package containing Scanner
    public class Name1

    {
    public static void main(String[] args)
    {

    //input

    Scanner kybd = new Scanner(System.in);

    System.out.println("Enter A Phrase");

    String phrase = kybd.nextLine();

    String name1 = "Cathy";
    String name2 = "Pete";
    String name3 = "Graham";

    if ((name1)||(name2)||(name3))

    System.out.println ("Data entered is valid");
    }
    }
  • Oct 13, 2007, 01:48 PM
    albear
    Anybody?
  • Oct 13, 2007, 02:24 PM
    albear
    Anything at all...
  • Nov 14, 2007, 09:29 PM
    qcumber
    Should be

    If( phrase.equals(name1) || phrase.equals(name2) || phrase.equals(name3) )
    {
    System.out.println ("Data entered is valid");
    }

  • All times are GMT -7. The time now is 11:39 AM.