• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

HSpringX

大学生入门笔记
  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

运算符

public class Test3 {
    public static void main(String[] args) {
        int a = 3;
        int b = a++;//a++。先把a赋值给b,a再自增
        System.out.println("a++之后的a为:"+a);
        int c = ++a;//++a。先a自增,再把a赋值给c
        System.out.println("a的值为:"+a);
        System.out.println("b的值为:"+b);
        System.out.println("c的值为:"+c);
        double pow = Math.pow(2, 3);
        System.out.println("=================");
        /*逻辑运算符
        &&短路与 有假则假
        ||短路或 有真则真
        短路就不会进行下一步
         */
        int d = 3;
        boolean e = (d>4)&&(d++>3);
        System.out.println(e);
        System.out.println(d);//d没有进行自增,所以没有进行后面的判断
        System.out.println("=================");
        /*三元运算符
        x?y:z
        如果x为真则返回y,否则返回z
         */
        int score = 80;
        String s = score < 60 ? "不及格" : "及格";
        System.out.println(s);
    }
}

输出:

a++之后的a为:4
a的值为:5
b的值为:3
c的值为:5
=================
false
3
=================
及格

 

posted on 2021-12-24 20:01  HSpringX  阅读(23)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3