doujiao7679 2013-05-14 02:05
浏览 45
已采纳

在Java中切换案例逻辑表达式语句 - 与JS或PHP

in JavaScript and also I've seen it in PHP : You can use a logical expression inside you cases : For Example :

switch(true){
case (d<10):
document.write("Less than 10");
break;
case (d==10):
document.write("Equal to 10");
break;
case (d>10):
document.write("Greater than 10");
break;
default:
document.write("Some dumb error. Probably not a number.");
}

I was wondering if we can do this in Java ... say I needed a to compare a very large range.

case 1 :
case 2 :
...
case 5000:
case 5001:
default:

It would be tedious to do. I could wrap my cases inside if statements but i was wondering it could be done like in JavaScript or PHP.

  • 写回答

2条回答 默认 最新

  • dsuw85815 2013-05-14 02:10
    关注

    No You cannot do that using switch in java. You have to use if-else to accomplish this.

    See this <kbd>link</kbd> for more details.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题