在Java中制作MadLib-用户输入错误

在Java中制作MadLib-用户输入错误,java,input,Java,Input,我对Java非常陌生,我正在尝试制作一个madlib,它接受用户输入并将其插入到一个句子中。到目前为止,我运气不太好。当我运行程序时,它会提示我输入第一个输入,但之后它会出错。你知道为什么吗?我认为它与数据类型(int、string等)有关 附加问题:插入段落后,如何使输入显示为粗体?假设我可以让这个代码在第一时间工作 这是我的密码: import java.util.Scanner; public class Madlib { public static void main(String

我对Java非常陌生,我正在尝试制作一个madlib,它接受用户输入并将其插入到一个句子中。到目前为止,我运气不太好。当我运行程序时,它会提示我输入第一个输入,但之后它会出错。你知道为什么吗?我认为它与数据类型(int、string等)有关

附加问题:插入段落后,如何使输入显示为粗体?假设我可以让这个代码在第一时间工作

这是我的密码:

import java.util.Scanner;

public class Madlib
{
  public static void main(String[] args)
  {
     int firstName, childAge, colorToy, typeToy;
     Scanner input = new Scanner(System.in);

     System.out.println("Enter someone's first name:");
     firstName = input.nextInt();
     System.out.println("Enter a child's age:");
     childAge = input.nextInt();
     System.out.println("Enter a color:");
     colorToy = input.nextInt();
     System.out.println("Enter a toy:");
     typeToy = input.nextInt();

     System.out.println("\"I am" + childAge + "years old, so that means I get to have the" + colorToy + typeToy + "!\" exclaimed the little girl.");
     System.out.println("\"Share with your sister,\"" + firstName + "grovelled, barely peering over their large, Sunday newspaper.");
   }
}

您出现此错误是因为

firstName, childAge, colorToy, typeToy
不应该都是整数。它们应该是你应该做的事情

firstName = input.nextLine();
childAge = input.nextLine();
colorToy = input.nextLine();
typeToy = input.nextLine();
而且,这不是你问题的一部分;然而,当你

System.out.println("\"I am " + childAge + " years old, so that means I get to have the " + colorToy + " " + typeToy + "!\" exclaimed the little girl.");
System.out.println("\"Share with your sister,\"" + " " + firstName + " grovelled, barely peering over their large, Sunday newspaper.");

它应该是这样的,在没有空间的地方包含空间。我希望这回答了你的问题

1-你说的“madlib”是什么意思?肯定不是
madlib
问号所涵盖的内容。2-加粗取决于输出介质,没有通用的加粗方法。我假设当你询问某人的名字时,你不希望输入整数。那么,为什么行
firstName=input.nextInt()?我对编码是新手,所以我只是想弄清楚类型以及Java如何处理它们。就madlib的事情而言,就我所学的而言,这是一个madlib。被告知提供输入,然后插入句子。“madlib”还有别的定义吗?我自己弄明白了。将int更改为string。昨天我的大脑很紧张,但至少我学到了一些东西。非常感谢。