Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Input method

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Input method

    I cannot implement this 'if' statement that I am trying to use on my console oriented text game.
    Basically, I thought there was an "input" method where the user would input a string of characters into the console.
    So I thought this would mean, if the user types in "Start", etc.
    Please bare with me, I am completely new to programming.

    if(input.equalsIgnoreCase("Start")){

    Apparently, it cannot find symbol "input".
    Can anybody help me out on what to write for an input class, for which users input a string of characters into the console, and it is read through these if statements.


  2. #2
    Member DavidFongs's Avatar
    Join Date
    Oct 2010
    Location
    Minneapolis, MN
    Posts
    107
    Thanks
    1
    Thanked 45 Times in 41 Posts

    Default Re: Input method

    There is no implicit variable named input that holds user entered input.

    You can use the Java class Scanner (Java Platform SE 6) to read in input (That's a link). There is an example in the javadoc.

  3. #3
    Member
    Join Date
    Feb 2010
    Posts
    30
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Input method

    You can accept input like this:

    import java.util.Scanner;
     
    public class Testt
    {
    	public static void main(String[] args)
    	{
    		String input;
    		Scanner s = new Scanner(System.in);
     
    		System.out.println("Enter your input");
    		input = s.nextLine();
     
    		System.out.println(input);
    	}
    }

    Make sure to import the Scanner class.

  4. #4
    Member DavidFongs's Avatar
    Join Date
    Oct 2010
    Location
    Minneapolis, MN
    Posts
    107
    Thanks
    1
    Thanked 45 Times in 41 Posts

    Default Re: Input method

    How is spoonfeeding the guy the answer better than linking him the javadoc and letting him figure it out? There is value in learning how to read a javadoc.

Similar Threads

  1. Can i call init() method in destroy method.?
    By muralidhar in forum Java Servlet
    Replies: 1
    Last Post: October 22nd, 2010, 11:18 AM
  2. Getting input
    By BuhRock in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 22nd, 2010, 10:30 AM
  3. [SOLVED] allow a new input, dicarding the last mismatch input without terminating the program
    By voltaire in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 9th, 2010, 04:44 AM
  4. Input Validation
    By nic in forum AWT / Java Swing
    Replies: 4
    Last Post: November 18th, 2009, 10:54 AM
  5. Values of Input
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: November 8th, 2009, 03:46 AM