• 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);
            }
    
        }
    
    }
  • 相关阅读:
    Java RandomAccessFile与MappedByteBuffer
    Apache httpClient
    gitolite migration to bitbucket
    logback身份证脱敏
    身份证号码-正则表达式
    webservice-整理
    Java高编译低运行错误(ConcurrentHashMap.keySet)
    IIS(互联网信息服务)
    ASP.NET MVC:UrlHelper.cs
    TortoiseSVN 和 VisualSVN
  • 原文地址:https://www.cnblogs.com/lwj820876312/p/7193965.html
Copyright © 2020-2023  润新知