Learn java step by step day6

1.Operational character


2.Arithmetic operator

public class AeithmeticOperator{
	public static void main(String[] args) {
		System.out.println(10 / 4);//2
		System.out.println(10.0 / 4);//2.5
		double d = 10 / 4;//2.0
		System.out.println(d);
        
        //%的本质 a % b = a - a / b * b
        System.out.println(10 % 3);//1
        System.out.println(-10 % 3);//-1
        System.out.println(10 % -3);//1
        System.out.println(-10 % -3);//-1

        //++
        int i = 10;
        i++;
        ++i;
        System.out.println("i=" + i);//12

        /*
        作为表达式使用 
        前++:++i 先自增后赋值 
        后++:i++先赋值后自增 
        */
       int j = 8;
       int k = ++j;//先自增后赋值
       int k = j++;//先赋值后自增
       System.out.println("k=" + k + "j=" + j );//9 9 8 9
	}
}

 3.Arithmetic operator exrecise

public class ArithmeticOperatorExercise{
	public static void main(String[] args) {
		//first question
		int b = 1;
		b = b++;//(1)temp = b;(2)b = b + 1;(3)b = temp;
		System.out.println(b);//1

		//Sceond question
		int a = 1;
		a = ++a;//(1)a = a + 1;(2)temp = a;(3)a = temp;
		System.out.println(a);//2

		//Third questiomn
		int i1 = 10;
		int i2 = 20;
		int i = i1++;
		System.out.print("i=" + i);//10
		System.out.println("i2=" + i2);//20 
        i = --i2;
        System.out.print("i=" + i);//19
        System.out.println("i2=" + i2);//19

        //Fourth question
        int allday = 59;
        int week = allday / 7;
        int day = allday % 7;
        System.out.println("合" + week + "个星期零" + day + "天" );

        //Fifth question
        double fahrenheit = 234.6;
        double centigrade = 5.0 / 9 * (fahrenheit - 100);
        System.out.println("华氏温度" + fahrenheit + "=摄氏温度" + centigrade);
	}
}

4.Relational operator(Comparison operator)

 


 5.Logical operator

 


 The knowledge learning in the article comes from

【零基础 快速学Java】韩顺平 零基础30天学会Java_哔哩哔哩_bilibiliicon-default.png?t=M1L8https://www.bilibili.com/video/BV1fh411y7R8?p=32

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值