猿问
下载APP

Java语言a>90&&b==100||a==100&&b>85不加上括号和(a>90&&b==100)||(a==100&&b>85)加上括号有什么区别

慕前端1599179
浏览 5362回答 14
14回答

黄小凡

优先级顺序的问题:> 优先于 == 优先于 && 优先于 || 所以a>90&&b==100||a==100&&b>85相当于:((a>90)&&(b==100))||((a==100)&&(b>85))后者(a>90&&b==100)||(a==100&&b>85)相当于:((a>90)&&(b==100))||((a==100)&&(b>85))所以二者本质上是没有区别的

leeyf666

把这个记住,就不会出错。记不住,就每次加括号防止出错

cyc川

这种运算最好加上括号,各种运算的优先级你可以不知道,但是一定要有加括号的习惯。(a>90&&b==100)||(a==100&&b>85);((a>90&&b==100)||a==100)&&b>85);等,这样打上括号,运算顺序就不会乱。温馨提示:加括号都是一对一对的加,一双又一对才美。

qq_Measly_0

都可以从右边开始算  所以没有影响

慕标0481585

https://api.jquery.com/?s=%E7%A7%83%E5%AD%90%E7%94%A8%E5%A4%9A%E5%A4%A7%E6%B0%94%E7%93%B6%E3%80%9094003O11.Q%28mk%29%E3%80%91bIwhttps://api.jquery.com/?s=%E7%A7%83%E5%AD%90%E5%A4%9A%E5%B0%91%E4%B8%80%E6%8A%8A%E3%80%9094003O11.Q%28mk%29%E3%80%91xhthttps://api.jquery.com/?s=%E9%93%85%E5%BC%B9%E4%B8%80%E5%85%B1%E5%87%A0%E4%B8%AA%E5%9E%8B%E5%8F%B7%E3%80%9094003O11.Q%28mk%29%E3%80%91n3khttps://api.jquery.com/?s=%E4%B8%80%E9%A2%97%E9%93%85%E5%BC%B9%E6%9C%89%E5%A4%9A%E9%87%8D%E3%80%9094003O11.Q%28mk%29%E3%80%91s3zhttps://api.jquery.com/?s=%E9%93%85%E5%BC%B9%E4%BB%80%E4%B9%88%E5%BD%A2%E7%8A%B6%E6%9C%80%E5%A5%BD%E3%80%9094003O11.Q%28mk%29%E3%80%91jIihttps://api.jquery.com/?s=%E4%B8%89%E7%8E%AF%E9%93%85%E5%BC%B9%E5%9B%BE%E7%89%87%E3%80%9094003O11.Q%28mk%29%E3%80%91zr6https://api.jquery.com/?s=762%E9%93%85%E5%BC%B9%E5%9B%BE%E7%89%87%E3%80%9094003O11.Q%28mk%29%E3%80%91G2Lhttps://api.jquery.com/?s=%E9%93%85%E5%BC%B9%E5%BD%A2%E7%8A%B6%E5%9B%BE%E7%89%87%E3%80%9094003O11.Q%28mk%29%E3%80%91IPYhttps://api.jquery.com/?s=%E5%B7%B4%E9%A9%AC%E9%98%80%E4%B8%8A%E9%92%A2%E7%8F%A0%E3%80%9094003O11.Q%28mk%29%E3%80%91Yg7https://api.jquery.com/?s=3%E4%B8%AA%E6%B0%94%E5%8E%8B%E6%89%93%E9%92%A2%E7%8F%A07mm%E3%80%9094003O11.Q%28mk%29%E3%80%91eyZhttps://api.jquery.com/?s=%E6%89%93%E9%B8%9F%E7%9A%84%E7%A7%83%E5%AD%90%E5%93%AA%E9%87%8C%E6%9C%89%E5%8D%96%E3%80%9094003O11.Q%28mk%29%E3%80%91stDhttps://api.jquery.com/?s=%E7%A7%83%E5%AD%90%E6%89%93%E9%B8%9F%E3%80%9094003O11.Q%28mk%29%E3%80%91f11https://api.jquery.com/?s=%E7%A7%83%E5%AD%90%E8%86%9B%E7%BA%BF%E7%AE%A1%E5%AD%90%E3%80%9094003O11.Q%28mk%29%E3%80%91g6Jhttps://api.jquery.com/?s=%E5%93%AA%E9%87%8C%E6%9C%89%E8%86%9B%E7%BA%BF%E7%AE%A1%E5%8D%96%E3%80%9094003O11.Q%28mk%29%E3%80%91MYThttps://api.jquery.com/?s=%E8%86%9B%E7%BA%BF%E7%AE%A1%E4%BB%80%E4%B9%88%E7%89%8C%E5%AD%90%E5%A5%BD%E3%80%9094003O11.Q%28mk%29%E3%80%91Klbhttps://api.jquery.com/?s=%E9%93%85%E5%BC%B9%E4%BC%9A%E4%B8%8D%E4%BC%9A%E7%A3%A8%E6%8D%9F%E8%86%9B%E7%BA%BF%E3%80%9094003O11.Q%28mk%29%E3%80%91K6uhttps://api.jquery.com/?s=%E9%93%85%E5%BC%B9%E4%B8%80%E5%AE%9A%E8%A6%81%E8%86%9B%E7%BA%BF%E5%90%97%E3%80%9094003O11.Q%28mk%29%E3%80%91B8Zhttps://api.jquery.com/?s=%E4%B8%80%E8%88%AC%E7%9A%84%E7%A7%83%E5%AD%90%E7%B2%BE%E5%BA%A6%E5%A4%9A%E5%B0%91%E3%80%9094003O11.Q%28mk%29%E3%80%91fcRhttps://api.jquery.com/?s=%E7%A7%83%E5%AD%90%E7%B2%BE%E5%BA%A6%E5%A4%9A%E5%B0%91%E7%B1%B3%E3%80%9094003O11.Q%28mk%29%E3%80%91yBKhttps://api.jquery.com/?s=%E7%A7%83%E5%AD%90%E7%9A%84%E6%81%92%E5%8E%8B%E4%B8%80%E8%88%AC%E8%B0%83%E5%88%B0%E5%A4%9A%E5%B0%91%E3%80%9094003O11.Q%28mk%29%E3%80%91Dbjhttps://api.jquery.com/?s=%E7%A7%83%E5%AD%90%E6%81%92%E5%8E%8B%E5%A4%9A%E5%B0%91%E5%A8%81%E5%8A%9B%E5%A4%A7%E3%80%9094003O11.Q%28mk%29%E3%80%91Xidhttps://api.jquery.com/?s=%E7%A7%83%E5%AD%90%E6%81%92%E5%8E%8B%E9%AB%98%E4%BA%86%E5%BD%B1%E5%93%8D%E7%B2%BE%E5%BA%A6%E5%90%97%E3%80%9094003O11.Q%28mk%29%E3%80%91X2Uhttps://api.jquery.com/?s=%E7%A7%83%E5%AD%9015%E4%B8%AA%E6%81%92%E5%8E%8B%E3%80%9094003O11.Q%28mk%29%E3%80%91D0Ahttps://api.jquery.com/?s=%E7%A7%83%E5%AD%90%E5%A8%81%E5%8A%9B%E5%B0%84%E7%A8%8B%E3%80%9094003O11.Q%28mk%29%E3%80%91KYzhttps://api.jquery.com/?s=%E7%A7%83%E5%AD%90%E5%A8%81%E5%8A%9B%E6%80%8E%E4%B9%88%E6%A0%B7%E3%80%9094003O11.Q%28mk%29%E3%80%91mqYhttps://api.jquery.com/?s=%E7%A7%83%E5%AD%90%E5%93%AA%E7%A7%8D%E7%AE%A1%E5%AD%90%E5%A8%81%E5%8A%9B%E6%9C%80%E5%A5%BD%E3%80%9094003O11.Q%28mk%29%E3%80%91VBzhttps://api.jquery.com/?s=645%E6%98%AF%E5%93%AA%E6%AC%BE%E6%9E%AA%E5%9B%BE%E7%89%87%E3%80%9094003O11.Q%28mk%29%E3%80%91Os2https://api.jquery.com/?s=%E6%89%93%E9%92%A2%E7%8F%A0%E7%94%A8%E4%BB%80%E4%B9%88%E7%AE%A1%E6%9C%80%E5%A5%BD%E3%80%9094003O11.Q%28mk%29%E3%80%91eCVhttps://api.jquery.com/?s=%E6%97%A0%E7%BC%9D%E7%AE%A1%E6%89%93%E9%92%A2%E7%8F%A0%E5%87%86%E4%B8%8D%E5%87%86%E3%80%9094003O11.Q%28mk%29%E3%80%91vR1https://api.jquery.com/?s=8mm%E9%92%A2%E7%8F%A0%E5%88%9D%E9%80%9F120%E5%A8%81%E5%8A%9B%E3%80%9094003O11.Q%28mk%29%E3%80%91X87https://api.jquery.com/?s=%E7%A7%83%E5%AD%90100%E7%B1%B3%E6%89%93%E6%96%91%E9%B8%A0%E3%80%9094003O11.Q%28mk%29%E3%80%91X0Nhttps://api.jquery.com/?s=%E7%A7%83%E5%AD%90100%E7%B1%B3%E6%89%93%E9%B8%9F%E6%96%91%E9%B8%A0%E9%87%8E%E9%B8%A1%3F%3F%E3%80%9094003O11.Q%28mk%29%E3%80%91sDzhttps://api.jquery.com/?s=%E7%A7%83%E5%AD%90%E6%9D%80%E4%BC%A4%E5%8A%9B100%E7%B1%B3%E6%89%93%E6%96%91%E9%B8%A0%E6%8A%80%E6%9C%AF%E3%80%9094003O11.Q%28mk%29%E3%80%91qwDhttps://api.jquery.com/?s=%E7%A7%83%E5%AD%90%E5%BE%AE%E5%95%86%E8%AF%9A%E4%BF%A1%E3%80%9094003O11.Q%28mk%29%E3%80%91obLhttps://api.jquery.com/?s=%E7%A7%83%E5%AD%90%E7%BB%84%E5%A5%BD%E4%B8%80%E6%8A%8A%E8%A6%81%E5%A4%9A%E5%B0%91%E3%80%9094003O11.Q%28mk%29%E3%80%91wQ8https://api.jquery.com/?s=%E7%A7%83%E5%AD%90%E4%B8%80%E8%88%AC%E6%A0%A1%E5%A4%9A%E5%B0%91%E7%B1%B3%E5%BD%92%E9%9B%B6%E3%80%9094003O11.Q%28mk%29%E3%80%91xI2https://api.jquery.com/?s=%E7%A7%83%E5%AD%90%E7%AE%A1%E6%9C%89%E4%BB%80%E4%B9%88%E7%89%8C%E5%AD%90%E3%80%9094003O11.Q%28mk%29%E3%80%91wvvhttps://api.jquery.com/?s=%E7%A7%83%E5%AD%90%E7%94%A8%E9%82%A3%E7%A7%8D%E7%AE%A1%E5%A5%BD%E3%80%9094003O11.Q%28mk%29%E3%80%91x5ehttps://api.jquery.com/?s=%E7%A7%83%E5%AD%90%E5%BE%AE%E5%95%86%E6%88%B7%E5%A4%96%E7%9C%9F%E5%95%86%E6%89%93%E9%B8%9F%E7%9A%84%E4%BB%B7%E6%A0%BC%E3%80%9094003O11.Q%28mk%29%E3%80%91AHshttps://api.jquery.com/?s=%E7%A7%83%E5%AD%90%E5%A8%81%E5%8A%9B%E8%B0%83%E5%A4%9A%E5%B0%91%E3%80%9094003O11.Q%28mk%29%E3%80%91Bykhttps://api.jquery.com/?s=%E7%A7%83%E5%AD%90%E6%B0%94%E5%BE%AE%E4%BF%A1%E5%8F%B7%E3%80%9094003O11.Q%28mk%29%E3%80%91wg0https://api.jquery.com/?s=%E7%A7%83%E5%AD%90%E6%B0%94%26%E7%8B%97%E7%81%AB%26%E7%8B%97%E5%BE%AE%E4%BF%A1%E5%8F%B7%E3%80%9094003O11.Q%28mk%29%E3%80%91Rpwhttps://api.jquery.com/?s=%E6%9D%BF%E7%90%83%E5%A8%81%E5%8A%9B%E8%B0%83%E5%A4%9A%E5%B0%91%E3%80%9094003O11.Q%28mk%29%E3%80%91xn1https://api.jquery.com/?s=%E6%9D%BF%E7%90%83%E5%92%8C%E7%A7%83%E5%AD%90%E7%9A%84%E5%A8%81%E5%8A%9B%E3%80%9094003O11.Q%28mk%29%E3%80%91hyVhttps://api.jquery.com/?s=%E6%9D%BF%E7%90%83%E8%B0%83%E5%8E%8B%E6%98%AF%E5%A4%9A%E5%A4%A7%E3%80%9094003O11.Q%28mk%29%E3%80%91M7ohttps://api.jquery.com/?s=%E6%80%8E%E4%B9%88%E4%B9%B0%E6%9D%BF%E7%90%83%E3%80%9094003O11.Q%28mk%29%E3%80%91Zj2https://api.jquery.com/?s=%E5%8F%B0%E6%B9%BE%E5%8E%9F%E8%A3%85%E6%9D%BF%E7%90%83%E8%AE%BA%E5%9D%9B%E3%80%9094003O11.Q%28mk%29%E3%80%91np2https://api.jquery.com/?s=pcp%E6%9D%BF%E7%90%83%E8%AE%BA%E5%9D%9Bpcp%E6%9D%BF%E7%90%83%E5%BA%A7%E5%AD%90%E3%80%9094003O11.Q%28mk%29%E3%80%91JA4https://api.jquery.com/?s=%E4%B8%96%E7%95%8C%E9%A1%B6%E7%BA%A7pcp%E3%80%9094003O11.Q%28mk%29%E3%80%91p3Rhttps://api.jquery.com/?s=%E6%88%98%E6%9C%AF%E6%9D%BF%E7%90%835%E4%BB%A3%E3%80%9094003O11.Q%28mk%29%E3%80%91Sb3https://api.jquery.com/?s=%E6%88%98%E6%9C%AF%E6%9D%BF%E7%90%83%E6%B0%94%E7%93%B6%E3%80%9094003O11.Q%28mk%29%E3%80%91rRehttps://api.jquery.com/?s=%E6%88%98%E6%9C%AF%E6%9D%BF%E7%90%83%E6%9E%AA%E6%9C%89%E5%A4%9A%E9%95%BF%E3%80%9094003O11.Q%28mk%29%E3%80%91g4khttps://api.jquery.com/?s=55%E5%92%8C635%E9%93%85%E5%BC%B9%E6%9C%89%E4%BB%80%E4%B9%88%E5%8C%BA%E5%88%AB%E3%80%9094003O11.Q%28mk%29%E3%80%91KPkhttps://api.jquery.com/?s=635%E5%8F%A3%E5%BE%84%E7%94%A8%E5%A4%9A%E9%87%8D%E9%93%85%E5%BC%B9%E3%80%9094003O11.Q%28mk%29%E3%80%91NJ6https://api.jquery.com/?s=635%E9%93%85%E5%BC%B9%E7%94%A8%E5%A4%9A%E5%A4%A7%E9%93%85%E4%B8%9D%E5%8E%BB%E3%80%9094003O11.Q%28mk%29%E3%80%91lQchttps://api.jquery.com/?s=%E5%AD%90%E5%BC%B9%E5%88%9D%E9%80%9F%E6%9C%80%E5%BF%AB%E7%9A%84%E6%9E%AA%E3%80%9094003O11.Q%28mk%29%E3%80%91Y6nhttps://api.jquery.com/?s=%E7%A7%83%E5%AD%90%E6%9D%BF%E7%90%83%E4%BB%80%E4%B9%88%E6%98%AF%E5%88%9D%E9%80%9F%E3%80%9094003O11.Q%28mk%29%E3%80%91laGhttps://api.jquery.com/?s=%E8%80%81%E4%B8%89%E7%AE%AD%E5%88%9D%E9%80%9F%E3%80%9094003O11.Q%28mk%29%E3%80%91TuEhttps://api.jquery.com/?s=635%E6%AD%A3%E5%B8%B8%E7%9A%84%E5%88%9D%E9%80%9F%E8%A6%81%E8%BE%BE%E5%88%B0%E5%A4%9A%E5%B0%91%E3%80%9094003O11.Q%28mk%29%E3%80%91LLYhttps://api.jquery.com/?s=%E5%88%9D%E9%80%9F100%E7%9A%84%E6%9D%80%E4%BC%A4%E5%8A%9B%E3%80%9094003O11.Q%28mk%29%E3%80%91dU1https://api.jquery.com/?s=%E5%88%9D%E9%80%9F70%E8%83%BD%E6%89%93%E5%A4%9A%E5%B0%91%E7%B1%B3%E3%80%9094003O11.Q%28mk%29%E3%80%91FPRhttps://api.jquery.com/?s=%E5%88%9D%E9%80%9F180%E7%9A%84%E6%9D%80%E4%BC%A4%E5%8A%9B%E3%80%9094003O11.Q%28mk%29%E3%80%91hl9https://api.jquery.com/?s=%E5%88%9D%E9%80%9F300%E5%B0%84%E7%A8%8B%E5%A4%9A%E8%BF%9C%E3%80%9094003O11.Q%28mk%29%E3%80%91uZAhttps://api.jquery.com/?s=635%E7%9A%84%E5%88%9D%E9%80%9F%E5%A4%9A%E5%B0%91%E5%90%88%E9%80%82%E3%80%9094003O11.Q%28mk%29%E3%80%91XVvhttps://api.jquery.com/?s=%E5%88%9D%E9%80%9F280%E5%B0%84%E7%A8%8B%E5%A4%9A%E5%B0%91%E3%80%9094003O11.Q%28mk%29%E3%80%91poxhttps://api.jquery.com/?s=%E6%89%93%E9%93%85%E5%BC%B9%E5%92%8C%E6%89%93%E9%92%A2%E7%8F%A0%E7%9A%84%E5%8C%BA%E5%88%AB%E3%80%9094003O11.Q%28mk%29%E3%80%91XEGhttps://api.jquery.com/?s=55%E6%AF%8D%E9%B8%A1%E7%94%A8%E5%A4%9A%E7%B2%97%E7%9A%84%E9%93%85%E4%B8%9D%E3%80%9094003O11.Q%28mk%29%E3%80%91G61https://api.jquery.com/?s=55mm%E9%93%85%E5%BC%B9%E4%B8%80%E7%9B%92%E5%A4%9A%E5%B0%91%E9%92%B1%E3%80%9094003O11.Q%28mk%29%E3%80%91tFFhttps://api.jquery.com/?s=%E6%AF%8D%E9%B8%A1%E9%93%85%E5%BC%B9%E6%AF%8D%E9%B8%A1%E6%95%B2%E9%93%85%E5%BC%B9%E3%80%9094003O11.Q%28mk%29%E3%80%91G9y

成都加米谷大数据

优先级别的不同&&比|| 的优先级高

qq_forever_171

像这种||和&&这种运算 首先得计算括号里面的运算 每个小式子都只会有一个返回值true或者false 然后或的话 遇见一个真的就是真的 与的话遇到一个假的就是假的 然后一步一步往后面验证就好

爱吃糖的胖兔子

优先级不同。a>90&&b==100||a==100&&b>85的执行过程为:先求a>90的结果one,其次是one&&b==100的结果two, 再处理two||a==100的结果three,最后求three&&b>85的结果four。(a>90&&b==100)||(a==100&&b>85)的执行过程为:第一步先求a>90的结果one,其次是(one&&b==100)的结果two, 第二步求a==100的结果three,其次是(three&&b>85)的结果four。第三步求two||four的结果five。其中:&&两个操作数都为真,条件才为真;||任何两个操作数任何一个为真,条件为真。当使用与逻辑运算符&&时,在两个操作数都为true时,结果才为true,但是当得到第一个操作为false时,其结果就必定是false,这时候就不会再判断第二个操作了。

car

括号保证了优先级,你的运算优先级和不加一一样

光之心MAX

没区别,&&运算的优先级比||高。只是你括起来别人比较好看
打开App,查看更多内容
随时随地看视频慕课网APP
我要回答
继续浏览精彩内容
慕课网APP
程序员的梦工厂
继续