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

    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(;
    		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
    Waterford, Ireland
    Rep Power

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