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

Thread: error with "Scanner" class in basic calculator program.

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default error with "Scanner" class in basic calculator program.

    Hello all, I am new to the community so sorry if I don't post the correct way. Will do the best that I can.
    Here is my code.I am using a IDE (eclipse) and it doesn't show me any errors. But every time I try to run it in CMD but I get a error saying "cannot find symbol class in = new Scanner" Any help would be much appreciated!

    public class HelloApp
    {
    	public static void main(String [] args)
    	{
    		Scanner in = new Scanner( System.in);
     
    		int number1;
    		int number2;
    		int sum;
     
    		System.out.println("Hello!");
    		System.out.println("Welcome to my first java calculator!");
    		System.out.println("When you are ready, Input your first number!");
    		number1 = input.nextInt();               // User inputs first number
     
    		System.out.println("Okay, Now the second number please!");
    		number2 = input.nextInt();             	// User inputs second number
     
    		sum = number1 + number2;
     
    		System.out.printf ("Sum is %d\n", sum);
     
    	}
    }

    Very basic program so I doubt that anyones brain will be hurt over this, I am jsut so new that every key is confusing.


  2. #2
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: error with "Scanner" class in basic calculator program.

    just realized my indentation is off when i copy pasted it to the thread. indention is correct in actual file. sorry.

  3. #3
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: error with "Scanner" class in basic calculator program.

    HelloApp is the name of the class you wrote.

    Scanner is the name of a class you did not write but are attempting to use.
    System is the name of a class you did not write but are attempting to use.

    System is included by default. Scanner is not. You have to import the Scanner class to use it.

    import java.util.Scanner;

  4. #4
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: error with "Scanner" class in basic calculator program.

    Got it working thanks jps! quick question on the import of scanner. When importing it do I always have to put it before the class I am going to be using it in? or can I put the import statement withing the class brackets?

  5. #5
    Member
    Join Date
    Jun 2012
    Location
    Left Coast, USA
    Posts
    451
    My Mood
    Mellow
    Thanks
    1
    Thanked 97 Times in 88 Posts

    Default Re: error with "Scanner" class in basic calculator program.

    Quote Originally Posted by wheezebeez View Post
    quick question...can I put the import statement within the class brackets...
    What happens when you try it like that? Isn't that a quicker way to find the answer?

    Cheers!

    Z

Similar Threads

  1. "Program execution skips the "if" statement"!
    By antony1925 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 7th, 2012, 08:15 AM
  2. Find the important class in ".mse" file using Java program
    By ashwarth21 in forum Java Theory & Questions
    Replies: 3
    Last Post: March 13th, 2012, 08:43 PM
  3. [SOLVED] Card Program"War" Class help
    By Usoda in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 16th, 2012, 08:43 PM
  4. Replies: 3
    Last Post: December 7th, 2011, 02:03 AM
  5. Replies: 7
    Last Post: August 13th, 2011, 02:22 AM

Tags for this Thread