day02-运算符-三元运算符
This commit is contained in:
@@ -18,7 +18,7 @@ public class Demo10 {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
//定义2个变量,判断下哪个变量值更大,返回的是较大的整数值!!!
|
//定义2个变量,判断下哪个变量值更大,返回的是较大的整数值!!!
|
||||||
int a = 100;
|
int a = 100;
|
||||||
int b = 20;
|
int b = 200;
|
||||||
|
|
||||||
// int max = a>b?a:b;
|
// int max = a>b?a:b;
|
||||||
int max = a<b?b:a;
|
int max = a<b?b:a;
|
||||||
@@ -26,6 +26,7 @@ public class Demo10 {
|
|||||||
System.out.println("-----------------------------");
|
System.out.println("-----------------------------");
|
||||||
|
|
||||||
//判断下哪个值大?(表示出变量a大,它的值为100),提示:使用字符串拼接
|
//判断下哪个值大?(表示出变量a大,它的值为100),提示:使用字符串拼接
|
||||||
|
String str = a > b ? "变量a大,它的值为"+a: "变量b大,它的值为"+b;
|
||||||
|
System.out.println(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user