Results 1 to 2 of 2
  1. #1
    erthbound0 is offline Member
    Join Date
    Dec 2011
    Posts
    4
    Rep Power
    0

    Default Scanner type inputs

    How do I make it where I check to see if a users input from a scanner function matches a word? Here is the program I wrote that doesnt work.

    Java Code:
    import java.util.Scanner;
    public class enemy2 {
    	public static void main(String args[]){
    		System.out.println("Green, Red, or Orange?");
    		String action;
    		Scanner command1 = new Scanner(System.in);
    		action = command1.nextLine();
    		System.out.println("you have chosen "+action);
    		if action == orange;{
    			System.out.println("Good Choice!");
    		}
    		
    			
    	}
    }

  2. #2
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: Scanner type inputs

    Java Class names should have is first letter uppercased. To compare Strings use equals() method, not ==

    Have a look at String docs to see how its done.

    You WILL want to find out how to write an if statement aswell..

Similar Threads

  1. Help with 2-D Arrays and Inputs
    By CJ1031 in forum New To Java
    Replies: 2
    Last Post: 04-16-2011, 03:56 AM
  2. Changing Scanner input type
    By mlad in forum New To Java
    Replies: 13
    Last Post: 03-18-2010, 05:22 PM
  3. Someone plz help... how to block inputs
    By waklo99 in forum New To Java
    Replies: 4
    Last Post: 03-15-2010, 07:44 AM
  4. How to create this if many inputs?
    By sarahannel123 in forum New To Java
    Replies: 3
    Last Post: 05-18-2008, 05:22 PM
  5. Date Inputs
    By hiranya in forum AWT / Swing
    Replies: 3
    Last Post: 11-06-2007, 06:11 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
  •