如何在firstName和lastName之间放置一个空格

时间:2014-09-29 04:23:52

标签: java

我不知道为什么我的lastName和firstName正在打印而它们之间没有空格。请帮忙!

import java.util.Scanner;

public class LastNameFirstNameChapter3
{
    public static void main(String[] args)
    {
    Scanner stdIn = new Scanner(System.in);
    String firstName; // Users First Name
    String lastName;  // Users Last Name
    String age;          // Users Age

    System.out.print("Enter Your First Name: ");
    firstName = stdIn.nextLine(); 
    System.out.println("Hello " +""+ firstName + "!");
    System.out.print("Please Enter Your Last Name: ");
    lastName = stdIn.nextLine(); 
    System.out.println("Hello " + firstName +""+ lastName + "!");
    System.out.print("Enter Your Age: ");
    age = stdIn.nextLine(); 
    } // end main
}     // end class LastNameFirstNameChapter3

1 个答案:

答案 0 :(得分:2)

import java.util.Scanner;

public class LastNameFirstNameChapter3
{
    public static void main(String[] args)
    {
    Scanner stdIn = new Scanner(System.in);
    String firstName; // Users First Name
    String lastName;  // Users Last Name
    String age;          // Users Age

    System.out.print("Enter Your First Name: ");
    firstName = stdIn.nextLine(); 
    System.out.println("Hello " +" "+ firstName + "!");
    System.out.print("Please Enter Your Last Name: ");
    lastName = stdIn.nextLine(); 
    System.out.println("Hello " + firstName +" "+ lastName + "!");
    System.out.print("Enter Your Age: ");
    age = stdIn.nextLine(); 
    } // end main
}