Java零基础入门到精通_Day 2

18 算数运算符

+ - * / %  整数的运算只能得到整数 除非用浮点数进行运算(得到浮点数)

public class Base_002 {
    public static void main(String[] args) {
        double a  = 6.0;
        int b =4;
        System.out.println(a/b); //1.5
    }
}

19 字符的+操作

 

public class Base_002 {
    public static void main(String[] args) {
        int a =4;
        char b = 'A'; //65
        char c = 'a'; //97
        char d = '0'; //48
        System.out.println(a+b); //69
        System.out.println(a+c); //101
        System.out.println(a+d); // 52

//        char ch =a+c; //自定变为int类型
        int ch =a+c;
        System.out.println(ch); //101
//        int k = 10+12.1; //报错
        double k = 10+12.1; //报错
        System.out.println(k); //22.1
    }
}

20 字符串的+操作

public class Base_002 {
    public static void main(String[] args) {
        System.out.println("it "+"heima");
        System.out.println("heima"+666);
        System.out.println(666+"heima");
        System.out.println("heima"+6+44);
        System.out.println(4+6+"heima");
        System.out.println("33"+"22"+"sss");
//        it heima
//        heima666
//        666heima
//        heima644
//        10heima
//        3322sss

    }
}

21 赋值运算符

public class Base_002 {
    public static void main(String[] args) {
        short s =10;
        s +=10;
        System.out.println(s);
//        s = s+10; //报错不兼容的类型
        s = (short) (s+10);
        System.out.println(s);
    }
}

22 自增自减运算符

public class Base_002 {
    public static void main(String[] args) {
        int i =10;
        int j = i++;
        System.out.println(i); //11
        System.out.println(j); //10
    }
}

23 关系运算符

24 逻辑运算符号

25 短路逻辑运算符

26 三元运算符

public class Base_002 {
    public static void main(String[] args) {
        int a = 10;
        int b = 20;
        int max = a > b ? a : b;
        System.out.println(max); //20

    }
}

27 两只老虎

略 

(w1==w2)? true:flase

28 三个和尚

public class Base_002 {
    public static void main(String[] args) {
        int a = 10;
        int b = 20;
        int c = 15;
        int max = (a>b)? a:b ;
        int maxx = (max > c) ? max:c;
        System.out.println(maxx);

    }
}

29 数据输入

import java.util.Scanner;
public class Base_002 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int i = scanner.nextInt();
        System.out.println(i);
    }
}

30 三个和尚升级版本

31 顺序结构

32 if 语句

33 if else 语句

34 奇数偶数

35 if else if语句

36 考试奖励

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

XF鸭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值