JAVA if语句

if语句的相关概念

package com.itheima;

import java.util.Scanner;

public class 分支结构 {
    public static void main(String[] args) {

        //键盘录入
        int wine;
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入:");
        wine = sc.nextInt();


        //注意事项:
        //如果if下有多条语句,必须加上大括号
        //如果只有一条可以省略
        if(wine > 2) {
            System.out.println("可以");
        }
        else{
            System.out.println("不可以");
        }

        //对bool类型类型进行判断事,不要用==号
        boolean flag = false;
        if(flag = true) {
            System.out.println("flag的值位true");
        }
        if(flag==true){
            System.out.println("flag的值为ture");
        }

        //if  (if else)  (else)
        Scanner sc1=new Scanner(System.in);
        System.out.println("请录入成绩");
        int score = sc1.nextInt();
        //对异常数据进行校验
        //0-100合法数据
        if(score>=0&&score<=100) {
            //开分化等级
            if (score >= 90 && score <= 100) {
                System.out.println("A");
            } else if (score < 90 && score >= 60) {
                System.out.println("B");
            } else {
                System.out.println("C");
            }
        }
        else {
            System.out.println("数据不合法");
        }
    }
}

if语句的相关练习

package com.itheima;

import java.util.Scanner;

public class 判断与循环的习题 {
    public static void main(String[] args) {


        //简单练习
        int rank=1;
        if(rank==1){
            System.out.println("可以");

        }
        else{
            System.out.println("不可以");
        }


        //键盘录入会员的级别,商品总价为10000
        //会员1级  7折
        //会员2级  6折
        //会员3级  5折
        //无会员   不打折
        int price =10000;
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入会员的级别");
        int vip= sc.nextInt();
        if(vip==1){
            System.out.println("支付的金额为"+(price*0.7));
        }
        else if(vip==2){
            System.out.println("支付的金额为"+(price*0.6));
        }
        else if(vip==3){
            System.out.println("支付的金额为"+(price*0.5));
        }
        else {
            System.out.println("支付的金额为"+price);
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值