test020.java
public class test020
{
public static void main(String[] args)
{
//if else 条件语句
//语句序列中只有一条语句时,写法如下,但是不建议这样写,没有可读性
int a = 100;
if(a== 100)
System.out.println("a = " + a);
//语句序列省略时,可以末尾加分号,代替花括号,依然不建议这样写,可读性差
boolean b = false;
if(b);
boolean c = false;
if(c) {}
//
int x = 45;
int y = 12;
if(x > y)
{
System.out.println("变量x大于变量y");
}
else
{
System.out.println("变量x小于变量y");
}
//
int math = 95;
int english = 56;
if(math >= 60)
{
System.out.println("数学及格了");
}
else
{
System.out.println("数学不及格");
}
if(english > 59)
{
System.out.println("英语及格了");
}
else
{
System.out.println("英语不及格");
}
//三元运算符替代法
int a1 = 5;
int b1 = 0;
if(a1 > 0)
{
b1 = a1;
}
else
{
b1 = -a1;
}
int a2 = 5;
int b2 = 0;
b2 = a2 > 0 ? a2:-a2;
System.out.println("b1 = " + b1);
System.out.println("b2 = " + b2);
}
}