当我运行它时,它不会出于某种原因问我这个国家,但是如果我输入了什么东西,它就会在最后出现。我有必要在原来的问题后面加些什么吗?以下是我迄今所做的工作。
import java.util.Scanner;
public class MadLib
{
private static Scanner in = new Scanner(System.in);
public static void main(String [] args)
{
System.out.print("What country are you from and what is your name, also how old are you? ");
System.out.println("Enter your country > ");
String country = in.nextLine();
System.out.println("Enter your name > ");
String name = in.nextLine();
System.out.println("Enter you age > ");
int age = in.nextInt();
madlib(country,name,age);
}
public static void madlib(String country,String name,int age)
{
System.out.println(" I'm from "+country+" and my name is "+name+" , and I am "+age+" years old. ");
}
}发布于 2014-10-03 02:10:27
问这个问题的一行应该是println而不是print
System.out.println("What country are you from and what is your name, also how old are you? "); 不同之处:
Println()不会在新行上打印,它将用换行符或序列终止当前行。换句话说,println()将打印行尾字符,而print()则不会。如果在print()之后调用println(),则println()的参数将附加到要print()的参数。
来自(http://www.coderanch.com/t/394386/java/java/system-print-println)
https://stackoverflow.com/questions/26172226
复制相似问题