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 3 of 3

Thread: Simple input value from user

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Simple input value from user

    Hello,

    I'm not sure what is wrong with my code:

    import java.util.Scanner;
     
    public class Main {
     
     int age = 0;
     
     System.out.println("Enter your age: ");
     
                      // Read in values  
                    age = in.nextInt();
     
    }



    The in is underlined, telling me "cannot find symbol"
    Last edited by Oonaghmcd; April 10th, 2014 at 09:06 AM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Simple input value from user

    When do you declare the in variable?

    Without an SSCCE, it's going to be pretty impossible to help you.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    7
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Simple input value from user

    Quote Originally Posted by Oonaghmcd View Post
    Hello,

    I'm not sure what is wrong with my code:

    import java.util.Scanner;
     
    public class Main {
     
     int age = 0;
     
     System.out.println("Enter your age: ");
     
                      // Read in values  
                    age = in.nextInt();
     
    }



    The in is underlined, telling me "cannot find symbol"
    You didn't create a scanner. Try this
    import java.util.Scanner;
     
    public class Main {
    public static void main(String []args){
     
     
    Scanner scanner = new Scanner(System.in);
    System.out.println("Enter your age: ");
    System.out.println(scanner.nextLine());  
    }                      
    }

Similar Threads

  1. User input error help.
    By Puffy Fawter in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 16th, 2013, 08:01 PM
  2. User Input help
    By dx2731 in forum Java Theory & Questions
    Replies: 3
    Last Post: May 13th, 2013, 12:46 AM
  3. User Input help
    By lanmonster in forum What's Wrong With My Code?
    Replies: 20
    Last Post: January 20th, 2013, 10:44 AM
  4. Take user input
    By frabbi.cse in forum Java Theory & Questions
    Replies: 1
    Last Post: July 22nd, 2012, 12:48 PM
  5. Valid user input
    By ChristopherLowe in forum Java Programming Tutorials
    Replies: 1
    Last Post: June 21st, 2011, 04:53 PM