欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

java笔记学习之操作符

时间:2021-05-11 08:52:43|栏目:JAVA代码|点击:

0x001 算数运算符

    int num1 = 1, num2 = 2;
    System.out.println(num1 + num2); // 3
    System.out.println(num1 - num2); // -1
    System.out.println(num1 / num2); // 0 
    System.out.println(num1 * num2); // 2
    System.out.println(num1 % num2); //1

0x002 自增自减

    System.out.println(num1++); // 1
    System.out.println(num1); // 2
    System.out.println(num1--); // 2
    System.out.println(num1); // 1
    System.out.println(++num1); // 2
    System.out.println(--num1); // 1

0x003 关系操作符

    System.out.println((num1 < num2)); // true
    System.out.println((num1 > num2)); // false
    System.out.println(num1 == num2); // false
    System.out.println(num1 != num2); // true

0x004 逻辑操作符

    boolean boolean1 = false; 
    boolean boolean2 = true; 
    System.out.println(boolean1 && boolean2); // false
    System.out.println(boolean1 || boolean2); // true
    System.out.println(!boolean1); // true

0x005 直接操作符

    int i1 = 0x2f;
    int i2 = 0x2F;
    int i3 = 0177;
    char c1 = 0xffff;
    byte b1 = 0x7f;
    short s1 = 0x7f;
    long l1 = 100L;
    long l2 = 100l;
    float f1 = 1;
    float f2 = 1f;
    float f3 = 1F;
    double d1 = 1d;
    double d2 = 1D;
    System.out.println(i1); // 47
    System.out.println(i2); //47
    System.out.println(i3); // 127
    System.out.println(c1); // 
    System.out.println(b1); // 127
    System.out.println(s1); // 127
    System.out.println(l1); // 100
    System.out.println(l2); // 100
    System.out.println(f1); // 1.0
    System.out.println(f2); // 1.0
    System.out.println(f3); // 1.0
    System.out.println(d1); // 1.0
    System.out.println(d2); // 1.0

0x006 三元运算符

    int a = 0;
    boolean isSuccess = false;
    a = isSuccess ? 1 : 2;
    System.out.println(a);// 2

0x007 字符串+、+=

    String str = "";
    str = str + "1";
    str += "2";
    System.out.println(str);

0x008 类型转化

    int i = 100;
    long long1 = (long) i;
    System.out.println(long1);// 100
    long1 = i;
    System.out.println(long1);// 100
    long long2 = (long) 200;
    System.out.println(long2);// 200
    i = (int) long1;
    System.out.println(i); // 200
    
    float float1=0.1f; 
    float float2=0.9f;
    System.out.println((int) float1);// 转化int会被舍去
    System.out.println((int) float2);// 转化int会被舍去

上一篇:SpringBoot集成Swagger2的方法

栏    目:JAVA代码

下一篇:Spring中property-placeholder的使用与解析详解

本文标题:java笔记学习之操作符

本文地址:http://www.codeinn.net/misctech/119023.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有