if处理多分支结构

实例1

import java.util.Scanner;

/**
 * Created by liwenj on 2017/7/17.
 */
public class test7 {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        int money=input.nextInt();
        if(money>500){
            System.out.println("我要买一个凯迪拉克");
        }
        else if(money>100){
            System.out.println("我要买一个帕萨特");
        }
        else if(money>50){
            System.out.println("我要买一个伊兰特");
        }
        else if(money>10){
            System.out.println("我要买一个奥拓");
        }
        else{
            System.out.println("我要买一个拖拉机");
        }
    }
}

实例2

import java.util.Scanner;

/**
 * Created by liwenj on 2017/7/17.
 */
public class test8 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入是否是会员");
        String huiyuan = input.next();
        boolean f = huiyuan.equals("yes");
        System.out.println("请输入消费金额");
        double money = input.nextDouble();
        if (f) {
            if (money >= 200) {
                double dazhe = money * 0.75;
                System.out.println("你消费:" + dazhe);
            } else {
                double dazhe = money * 0.8;
                System.out.println("你消费:" + dazhe);
            }

        } else if (money >= 100) {
            double dazhe = money * 0.9;
            System.out.println("你消费:" + dazhe);
        }else{
            System.out.println("你消费:"+money);
        }

    }

}

 

posted @ 2017-07-17 14:03  斯丢皮德曼  阅读(754)  评论(0编辑  收藏  举报