【发布时间】:2020-12-27 17:35:06
【问题描述】:
从建议问题的答案中获取了一些信息并编辑了我的代码。现在我收到 || 运算符的错误。那里有什么问题?写这篇文章的正确方法是什么。
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String shapeName;
do {
System.out.println("Please identify the shape");
System.out.print("Rectangle (Press R) / Circle (Press C): ");
shapeName = input.next();
} while (!shapeName.equals("R") || !shapeName.equals("C"));
【问题讨论】:
-
只需将输入中的代码放入循环
while(True)并在有效情况下退出(例如break) -
如果你解释了你的代码有什么问题(即它没有退出循环)会很有帮助,因为如果你说你“得到一个错误”人们希望你得到一个运行时异常或编译时错误。