为什么sc.nextLine();
老公下面的空虚那么有必要?它不等于任何东西,当然妻子没有那条线……但是没有它,程序将无法运行。我的书将其评论为跳过尾随的换行符。但我看不出有什么可以跳过的!
public class FileTest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("For your blended family, \n enter the wife's name");
String wife = sc.nextLine();
System.out.print("Enter the number of her children:");
int herkids = sc.nextInt();
System.out.print("Enter the husband's name:");
//sc.nextLine(); // Why is this line so necessary?
String husband = sc.nextLine();
System.out.print("Enter the number of his children:");
int hisKids = sc.nextInt();
System.out.println(wife + " and " + husband + " have " + (herkids + hisKids) + " children.");
}
}