Results 1 to 4 of 4
  1. #1
    makeawish is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default Name Printer Program

    Hi,

    I am trying to write a simple program which allows a user to enter their name.

    This is what I've coded so far:

    Java Code:
    import java.util.Scanner;
    
    public class NamePrinter
    {
        public static void main(String[] args)
        {
            System.out.print("Please enter your name: ");
            String name = in.next();
        }
    }
    However, when I try to compile and run the program in cmd, I get 1 error: String name = in.next();
    .................................................. .................................................. ...................^

    The error is pointing to the 'i'. Does that mean something is wrong with the i or does that mean something is wrong with that line?

    I am confused with what I'm doing and I am unsure of what the error means when the ^ points to a particular part.

    Thanks for your help.
    Last edited by makeawish; 10-12-2010 at 09:15 PM.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    What is the compiler message? These messages are always helpful.

  3. #3
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    351
    Rep Power
    4

    Default

    It means you are calling a method which does not exist for the variable "in". What is "in"?
    Won't say any more than that ;).

    Regards.

  4. #4
    makeawish is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default

    Thanks for your replies. I changed it to and it worked:

    Java Code:
    import java.util.Scanner;
    
    public class NameReader
    {
    	public static void main(String[] args)
    	{
    
    	Scanner in = new Scanner(System.in);
    
    	System.out.print("Please enter your name: ");
    	String name = in.nextLine();
    	}
    }

Similar Threads

  1. How to connect to printer from a stand alone java program?
    By vidya.c@tcs.com in forum New To Java
    Replies: 0
    Last Post: 03-01-2010, 05:49 AM
  2. how to add a printer option in a java program?
    By Allgorythm in forum New To Java
    Replies: 1
    Last Post: 02-20-2010, 12:21 AM
  3. Replies: 2
    Last Post: 02-20-2009, 07:25 AM
  4. Replies: 0
    Last Post: 08-09-2007, 06:30 AM
  5. jsp program for client side printer to print these 2 strings on 3/3
    By for453 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 08-07-2007, 04:42 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
  •