java Day05-2
条件运算符
-
案例
package operator; public class Demo07 { public static void main(String[] args) { int a = 10; int b = 20; a+=b; //a = a+b a-=b; //a = a-b System.out.println(a); //字符串连接符 + , String System.out.println(""+a+b); //在后面是拼接 System.out.println(a+b+""); //在前面是继续运算 } } -
答案
10
1020
30
三元运算符
-
案例
package operator; //三元运算符 public class Demo08 { public static void main(String[] args) { // x ? y : z //如果x==ture,结果为y,否则为z int score = 80; String type = score < 60 ? "不及格":"及格"; //if System.out.println(type); } } -
答案
及格

浙公网安备 33010602011771号