How to do a case with multiple conditions?(多条件案件怎么办?)
问题描述
在我使用任何编程语言的 1 个月经验中,我假设 switch
case
条件将接受括号中的任何内容作为布尔检查 thingamajig, IE这些:
In the 1 month experience I've had with any programming language, I've assumed that switch
case
conditions would accept anything in the parenthesis as a boolean checking thingamajig, ie
these:
|| && < >
明白我的意思吗?
类似
char someChar = 'w';
switch (someChar) {
case ('W' ||'w'):
System.out.println ("W or w");
}
可悲的是,这种方式似乎并不奏效.我不能在开关盒中进行布尔检查.
Sadly, doesn't seem to work that way. I can't have boolean checking in switch case.
有办法解决吗?
顺便说一句,如果我听起来令人困惑,非常抱歉.我还不太清楚这种语言中所有内容的名称:X
任何答案表示赞赏
By the way, terribly sorry if I'm sounding confusing. I don't quite know the names for everything in this language yet :X
Any answers appreciated
推荐答案
对于这样的情况,您可以实现 OR:
You can achieve an OR for cases like this:
switch (someChsr) {
case 'w':
case 'W':
// some code for 'w' or 'W'
break;
case 'x': // etc
}
案例就像一个goto",多个 goto 可以共享同一行来开始执行.
Cases are like a "goto" and multiple gotos can share the same line to start execution.
这篇关于多条件案件怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:多条件案件怎么办?


基础教程推荐
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 降序排序:Java Map 2022-01-01