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: Collecting user input error

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    1
    My Mood
    Angry
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Collecting user input error

    Ok first time poster here so please post any pointers on posting and any help in general. I'm very new to Java programming but I started this way with C++ and love it, I hope I can do the same with Java.

    So my problem is that I'm trying to create a program that will collect the first and last name of a user, convert to all lower case letters, and put it in a generic email format (firstname.lastname@waketech.edu).
    Troubles I'm having are that I can't get the user input to ask and collect the input. I don't know where to put the .toLowerCase().

    import java.util.Scanner;
    public class EmailGenerator
    {
     
    	/**
    	 * This method is to grab the users input and convert to all lower case letters
    	 * and put in an email address with given host. 
    	 *
    	 * @param args
    	 */
    	public static void main(String[] args)
    	{
    		// TODO Auto-generated method stub
    		Scanner firstName = new Scanner (System.in);
    		System.out.print("Enter your first name: ");
    		System.out.println(firstName);
     
    		Scanner lastName = new Scanner (System.in);
    		System.out.print("Enter your last name: ");
    		System.out.print(lastName);
     
    		System.out.print(firstName);
    		System.out.print(lastName);
    		System.out.println("@waketech.edu");
     
     
     
    	}
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,106
    Thanks
    65
    Thanked 2,717 Times in 2,667 Posts

    Default Re: Collecting user input error

    You can use a single instance of the Scanner class for reading all the user input. There does not need to be one for each thing that is read.

    Read the API doc for the Scanner class methods. There are examples of how to use them. Various methods will return the values that the user enters. The code has to save the returned values in variables.

    What did the code print out?

    where to put the .toLowerCase().
    Read the API doc for the String class to see how to use that method.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Collecting user input error

    I would use the code:
    Scanner input = new Scanner(System.in);
     
    String firstName;
    String secondName;
     
    System.out.println("First Name");
    firstName = input.next;
    System.out.println("Second Name");
    secondName = input.next;
     
    System.out.println(firstName+secondName+"@waketech.edu");

Similar Threads

  1. Take user input
    By frabbi.cse in forum Java Theory & Questions
    Replies: 1
    Last Post: July 22nd, 2012, 12:48 PM
  2. User Input with a Do Loop
    By RadiantChaos in forum Loops & Control Statements
    Replies: 4
    Last Post: March 13th, 2012, 07:14 PM
  3. Valid user input
    By ChristopherLowe in forum Java Programming Tutorials
    Replies: 1
    Last Post: June 21st, 2011, 04:53 PM
  4. User Input File Name
    By PineAppleKing in forum Java Theory & Questions
    Replies: 12
    Last Post: June 3rd, 2011, 10:23 AM
  5. User Input Loop
    By cfmonster in forum Loops & Control Statements
    Replies: 7
    Last Post: August 24th, 2009, 01:52 PM

Tags for this Thread