gpt4 book ai didi

java - 我收到 - java.io.IOException 无法解析错误,尽管导入 IO

转载 作者:行者123 更新时间:2023-12-02 05:44:16 26 4
gpt4 key购买 nike

// Using a do-while to process a menu selection.

public class Menu {
public static void main(String args[]) throws java.io.IOException {
char choice;

do {
System.out.println("Help on: ");
System.out.println(" 1. if");
System.out.println(" 2. switch");
System.out.println(" 3. while");
System.out.println(" 4. do-while");
System.out.println(" 5. for\n");
System.out.println("Choose one: ");
choice = (char) System.in.read();
} while (choice < '1' || choice > '5');

System.out.println("\n");

switch (choice) {
case '1':
System.out.println("The if:\n");
System.out.println("if(condition) statement;");
System.out.println("else statement;");
case '2':
System.out.println("The switch:\n");
System.out.println("switch(expression) {");
System.out.println(" case constant:");
System.out.println(" statement sequence");
System.out.println(" break;");
System.out.println(" //...");
System.out.println("}");
break;
case '3':
System.out.println("The while:\n");
System.out.println("while(condition) statement;");
break;
case '4':
System.out.println("The do-while:\n");
System.out.println("do {");
System.out.println(" statement;");
System.out.println("} while (condition);");
break;
case '5':
System.out.println("The for:\n");
System.out.println("for(initialization; condition; iteration)");
System.out.println(" statement;");
break;
}
}
}

当我在 Eclipse IDE 中运行此程序时,出现此错误

Exception in thread “main” java.lang.Error: Unresolved compilation problem:
java.io.IOException cannot be resolved to a type at Menu.main(Menu.java:3)

我已经重建了项目,清理了几次,刷新仍然没有运气......:-(

最佳答案

您在此处提供的代码完美运行。

当您使用 Eclipse 作为 IDE 并尝试运行甚至无法编译的代码时,就会发生此错误。检查 Eclipse 中的问题 View ,并在执行应用程序之前修复编译错误。

关于java - 我收到 - java.io.IOException 无法解析错误,尽管导入 IO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24235273/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com