什么是运算符

本文深入探讨了Java中各种运算符的使用方法及其应用场景,包括算术运算符、赋值运算符、比较运算符、逻辑运算符和三元运算符等。通过具体的代码示例,读者可以了解到如何运用这些运算符进行数值计算、条件判断和表达式简化,为日常的编程工作提供实用的技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

什么是运算符

在这里插入图片描述

public class HelloWorld{
    public static void main(String[] args) {
		int a=12;
		int b=24;
		int sum = a + b;
		System.out.println("两数之和为:"+sum);
	}
}

在这里插入图片描述

public class HelloWorld{
    public static void main(String[] args) {
		int age1=24;
		int age2=18;
		int age3=36;
		int age4=27;
		int sum=age1+age2+age3+age4;
		double avg=sum/4;
		int minus=age1-age2;
		int newAge=--age1;
	    System.out.println("年龄总和:"+sum);
    	System.out.println("平均年龄:"+avg);
		System.out.println("年龄差值:"+minus);
		System.out.println("自减后的年龄:"+newAge);
	}
}

在这里插入图片描述

public class HelloWorld{
    public static void main(String[] args) {
	    int one = 10 ;
        int two = 20 ;
        int three = 0;
        three=one+two;
        System.out.println("three = one + two ==> " + three);
        three +=one;
        System.out.println("three += one ==>" +three);
        three -=one;
        System.out.println("three += one ==> " +three);
        three *=one;
        System.out.println("three += one==> " +three);
        three /=one;
        System.out.println("three += one ==> " +three);
        three %=one;
        System.out.println("three += one ==> " +three);
	}
}

在这里插入图片描述

public class HelloWorld{
    public static void main(String[] args) {
		int score=68;
		String mark = (score >60) ? "及格" :"不及格";
		System.out.println("考试成绩如何:"+mark);
	}
}

在这里插入图片描述

public class HelloWorld {
    public static void main(String[] args) {
		int m = 5;
		int n = 7;
		int x = (m*8/(n+2))%m;
		System.out.println("m:" + m);
		System.out.println("n:" + n);
		System.out.println("x:" + x);
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值