java - 在 Switch 菜单上使用 do-while 循环
问题描述
对不起
这个问题是不允许的,我受到了严厉的批评
解决方案
您可以通过简单地添加while
或do-while
循环来做到这一点
更新了你的方法。查看:
private void moduleSelection() {
int choice = -1;
while (true) {
System.out.println("1\t Algorithms");
System.out.println("2\t Advanced Programming");
System.out.println("3\t Computer Architecture and Operating Systems");
System.out.println("4\t Artificial intelligence and Machine Learning");
System.out.println("5\t Computer and Mobile Networks");
System.out.println("6\t Software Engineering");
System.out.println("7\t Big Data Analyics");
System.out.println("8\t Cyber Security Threats");
System.out.println("9\t Research Methods");
System.out.println("10\t Research Project Proposal");
System.out.println("11\t Individual Research Project");
System.out.println("0\t Exit");
System.out.println("Please entire your Module choice");
choice = scanner.nextInt();
switch (choice) {
case 0:
System.exit(1);
break;
case 1:
System.out.println("Algorithms");
break;
case 2:
System.out.println("Advanced Programming");
break;
case 3:
System.out.println("Computer Architecture and Operating Systems");
break;
case 4:
System.out.println("Artificial intelligence and Machine Learning");
break;
case 5:
System.out.println("Computer and Mobile Networks");
break;
case 6:
System.out.println("Software Engineering");
break;
case 7:
System.out.println("Big Data Analytics");
break;
case 8:
System.out.println("Cyber Security Threats");
break;
case 9:
System.out.println("Research Methods");
break;
case 10:
System.out.println("Research Project Proposal");
break;
case 11:
System.out.println("Individual Research Project");
break;
default:
System.out.println("Please select a valid Module");
break;
}
}
}
推荐阅读
- c++ - ./a.out 结果 '.' 未被识别为内部或外部命令、可运行程序或批处理文件
- javascript - 使用带有 Websockets 的 JavaScript MQTT 客户端连接到 MQTT 代理时出错
- amazon-web-services - terraform db 实例和 ec2 安全组位于不同的 vpc 中
- reactjs - 使用 React 的内联 CSS 样式块
- javascript - 在 JavaScript 中实现流
- entity-framework - 如何使用 count 、 group by 和 isnull 子句协调 SQL 查询到 LINQ
- load-balancing - 具有负载平衡 Web 服务器的 ITfoxtec SAML
- javascript - 在无名的父对象中调用带有空格的子对象
- regex - 正则表达式查找第二个 / 并开始计数 5 个字符
- excel - 当过滤器没有数据时跳过表的副本