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