用Java编写随机语句生成器
我正在尝试创建一个程序,生成英语中的随机句子(根据一般英语语法规则) 我的子例程用Java编写随机语句生成器,java,Java,我正在尝试创建一个程序,生成英语中的随机句子(根据一般英语语法规则) 我的子例程randomstation()不断出现错误。我错过了什么?还有关于如何简化一切的建议吗 我收到的错误是: Exception in thread "main" java.lang.Error: Unresolved compilation problem: The method print(boolean) in the type PrintStream is not applicable for the argu
randomstation()
不断出现错误。我错过了什么?还有关于如何简化一切的建议吗
我收到的错误是:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method print(boolean) in the type PrintStream is not applicable for the arguments (void)
at SentenceGenerator.randomSentence(SentenceGenerator.java:80)
at SentenceGenerator.main(SentenceGenerator.java:86)
代码:
这是最明显的错误:
public static void randomSentence() {
System.out.print(randomSentence());
}
您可以递归地调用该方法
此外,该程序充满了概念错误,您需要更好地研究OO编程范式。好的。第一期发行:
System.out.print(随机句子())代码>
randomstation()
返回void
,因此基本上没有任何内容可供print()
打印
下一步-->即使您碰巧解决了此问题。您正在递归调用randomSession()
,将得到一个stackOverflowerError
。请检查您的设计/代码。您所说的bug是什么意思?这是编译器错误吗?异常?…如果我没有错,您将得到一个StackOverflowerError
递归调用RandomSession()
。如果RandomSession返回了一些内容,则会出现这种情况。按原样,它不应该编译…这段代码什么都不做。如果你在这里询问编译错误,你永远也不会完成你的程序。试着自己解决问题,做一些调试。
public static void randomSentence() {
System.out.print(randomSentence());
}