码迷,mamicode.com
首页 > 其他好文 > 详细

基本运算符

时间:2021-03-06 14:45:10      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:java   复制   结果   alt   基本运算符   image   需要   布尔   强制转换   

技术图片

package operator;

public class Demo01 {
    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(a/b);//0 int类型只取整数部分
        System.out.println(a/(double)b);//0.5 需要强制转换
    }
}
public class Demo02 {
    public static void main(String[] args) {
        long a=121231231231L;
        int b=123;
        short c=10;
        byte d=8;
        System.out.println(a+b+c+d);//long 含有long类型就是long 含有double类型就是double
        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);//c除以a 取余数 21/10=2...1

        System.out.println(a>b);//false
        System.out.println(a<b);//true
        System.out.println(a==b);//false
        System.out.println(a!=b);//true


    }
}

基本运算符

标签:java   复制   结果   alt   基本运算符   image   需要   布尔   强制转换   

原文地址:https://www.cnblogs.com/styh/p/14488655.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!