1、条件运算符
type d = a ? b : c 如int d = 2 < 1 ? 3 : 4;
2、流程控制语句if用法
public class IfTest
{
public static void main(String[] args)
{
int a = 2;
int b = 2;
/*
if(a < b)
//if(a > b)
{
System.out.println("executed!");
}
*/
/*
if(a > b)
{
System.out.println("a > b");
}
else
{
System.out.println("a <= b");
}
*/
if(a > b)
{
System.out.println("a > b");
}
else if(a < b)
{
System.out.println("a < b");
}
else
{
System.out.println("a == b");
}
}
}
3.Switch语句
public class SwitchTest
{
public static void main(String[] args)
{
int a = 3;
/*
switch(a)
{
case 1:
System.out.println("a == 1");
break;
case 2:
System.out.println("a == 2");
break;
case 3:
System.out.println("a == 3");
//break;
default:
System.out.println("default");
}
*/
if(a == 1)
{
System.out.println("a == 1");
}
else if(a == 2)
{
System.out.println("a == 2");
}
else if(a == 3)
{
System.out.println("a == 3");
}
else
{
System.out.println("default");
}
}
}