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 如何提取csv文件中需要的列,将其整合为一篇完整文档,并进行jieba分词(语言-python)
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?