我不知道为什么我的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
答案 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
}