Log in

View Full Version : Using string class


albear
Oct 13, 2007, 01:06 PM
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");
}
}

albear
Oct 13, 2007, 01:48 PM
Anybody?

albear
Oct 13, 2007, 02:24 PM
Anything at all...

qcumber
Nov 14, 2007, 09:29 PM
Should be

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