首页 > 其他 > 详细

运算符

时间:2020-07-09 12:22:37      阅读:56      评论:0      收藏:0      [点我收藏+]

运算符

Java语言支持的运算符

  • 算数运算符:+,-,*,/,%,++,--

  • 赋值运算符:=

  • 关系运算符:>,<,>=,<=,==,!=,instanceof

  • 逻辑运算符:&&(与),||(或),!(非)

  • 位运算符:&,|,^,~,>>,<<,>>>(了解)

  • 条件运算符:? :

  • 拓展赋值运算符:+=,-=,*=,/=

 public static void main(String[] args) {
       //二级运算符
       //Ctrl + D:复制当前行到下一行
       int a = 10;
       int b = 20;
       int c = 30;
       int d = 40;
?
       System.out.println(a+b);
       System.out.println(a-b);
       System.out.println(a*b);
       System.out.println((double)a/b);//用到强制转换
  }

 

public class Demo02 {
?
   public static void main(String[] args) {
       long a = 123123123123123L;
       int b = 123;
       short c = 10;
       byte d = 8;
?
       System.out.println(a+b+c+d);//long
       System.out.println(b+c+d);//int
       System.out.println(c+d);//int
  }
?
}

 

 

public class Demo03 {
?
   public static void main(String[] args) {
       //关系运算符的返回结果:正确,错误   用布尔值表示
?
       int a = 10;
       int b = 20;
       int c = 21;
?
       //取余,模运算
       System.out.println(c%a); //结果为余数
?
       System.out.println(a>b);
       System.out.println(a<b);
       System.out.println(a==b);
       System.out.println(a!=b);
  }
?
}
?

 

运算符

原文:https://www.cnblogs.com/3556224176-zxt/p/13272868.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!