基本运算符

一、二元运算符
package operator;
public class Demo01 {
public static void main(String[] args) {
int a=10;
int b=20;
int c=25;
int d=25;
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println((double)a/b);
}
}
二、intresting!
package operator;
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);
System.out.println(b+c+d);
System.out.println(c+d);
}
}
三、关系运算符
package operator;
public class Demo03 {
public static void main(String[] args) {
int a=10;
int b=20;
int c=21;
System.out.println(a>b);
System.out.println(a<b);
System.out.println(a==b);
System.out.println(a!=b);
System.out.println(c%a);
}
}
四、自增自减运算符、初识Math类
package operator;
public class Demo04 {
public static void main(String[] args) {
int a=3;
int b=a++;
int c=++a;
System.out.println(a);
System.out.println(b);
System.out.println(c);
double pow=Math.pow(2,3);
System.out.println(pow);
}
}
五、逻辑运算符
package operator;
public class Demo05 {
public static void main(String[] args) {
boolean a=true;
boolean b=false;
System.out.println("a && b:"+(a && b));
System.out.println("a || b:"+(a || b));
System.out.println("!(a && b):"+(!(a && b)));
int c=5;
boolean d=(c<4)&&(c++<4);
System.out.println(d);
System.out.println(c);
}
}
六、位运算符
package operator;
public class Demo06 {
public static void main(String[] args) {
}
}
七、三元运算符
package operator;
public class Demo07 {
public static void main(String[] args) {
int a=10;
int b=20;
a+=b;
a-=b;
System.out.println(a);
System.out.println(a+b);
System.out.println(""+a+b);
System.out.println(a+b+"");
}
}
package operator;
public class Demo08 {
public static void main(String[] args) {
int s=80;
String t=s>60 ? "及格" : "不及格";
System.out.println(t);
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术