day14 Java基础——三元运算符(条件运算符)及小结
1.条件运算符(偷懒)
package operator;
public class Demo10 {
public static void main(String[] args) {
//x ? y : z
//如果x==true,则结果为y,否则结果为z
int score = 80;
String type = score <60 ?"不及格":"及格";
System.out.println(type);
}
}
及格
2。扩展赋值运算符(偷懒)
package operator;
public class Demo09 {
public static void main(String[] args) {
int a = 10;
int b = 20;
a+=b;//a = a+b
System.out.println(a);
}
}
30
3.字符串连接符 —— +
package operator;
public class Demo09 {
public static void main(String[] args) {
int a = 10;
int b = 20;
System.out.println(a+b);
System.out.println(""+a+b);
}
}
30
1020
面试题:(“”+a +b)与(a+b+“”)有什么区别?都是1020?
package operator;
public class Demo09 {
public static void main(String[] args) {
int a = 10;
int b = 20;
System.out.println(a+b);
System.out.println(""+a+b);
System.out.println(a+b+"");
}
}
30
1020
30
细节问题
4.优先级()
5.总结
素材引用
【【狂神说Java】Java零基础学习视频通俗易懂】 https://www.bilibili.com/video/BV12J41137hu/?p=30&share_source=copy_web&vd_source=7f3536a42709e7d479031f459d8753ab