0

当我运行它时,它不会出于某种原因要求我输入国家/地区,但如果我输入某些内容,它会在最后显示。我必须在原始问题之后添加一些内容吗?这是我到目前为止所做的。

    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. ");
      }
      }
4

1 回答 1

0

询问问题的行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

于 2014-10-03T02:10:27.487 回答