2.3.1
1.三个数比较大小
Scanner in = new Scanner(System.in);
int x = in.nextInt();
int y = in.nextInt();
int z = in.nextInt();
int max;
if(x>y)
{
if(x>z)
{
max = x;
}
else
{
max = z;
}
}
else
{
if(y>z)
{
max = y;
}
else
{
max = z;
}
}
System.out.println(max);
2.else总是和最近的if匹配
3.级联
(分段函数)
System.out.println(max);
if ( x < 0 )
{
f = -1;
}
else if ( x== 0 )
{
f = 0;
}
else
{
f = z * x;
2.3.2
1. switch-case
switch ( type )
{
case 1:
System.out.println("你好");
break;
case 2:
System.out.println("早上好");
break;
case 3:
System.out.println("晚上好");
break;
case 4:
System.out.println("再见");
break;
default:
System.out.println("^_^");