//单if语句
public class If {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("今天天气不错,去网吧");
int age = 19;
if (age >= 18) {
System.out.println("进入网吧");
System.out.println("开始骂人");
System.out.println("结账走人");
}
System.out.println("回家吃饭");
}
}
//标准的if - else语句
public static void main(){
int num = 222;
if (num % 2 == 0) {//如果除以2能够余数为0,说明是偶数
System.out.println("偶数");
}else {
System.out.println("奇数");
}
}
/*
* x和y的关系满足如下
*
* 如果x >= 3,那么 y = 2x + 1;
* 如果 -1 < x < 3,那么y = 2x;
* 如果x <= -1,那么 y = 2x-1;
*/
public static void name() {
int x = 10;
int y;
if (x >= 3) {
y = -2 * x + 1;
}else if (-1 < x && x < 3) {
y = 2 * x;
}else {
y = 2 * x - 1;
}{
System.out.println(y);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
//三元运算符
//int max = a > b ? a : b;
//if语句
int a = 10;
int b = 20;
int max;
if (a > b) {
max = a;
}else {
max = b;
}
System.out.println(max);
}
}