java学习笔记-逻辑运算符-2021.12.7

  早上起来终于能敲了一个scanner输入学生成绩的代码,能用if else判断输入的成绩是否在给的范围了。成果如下

import java.util.Scanner;

public class Demo1Operator {
 public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入学生的成绩:");
        int score = sc.nextInt();
        if (score >= 90 & score <= 100) {
            System.out.println("优秀!");
        }
        else {
            System.out.println("不是优秀成绩!");
        }

        System.out.println("请输入工号:");
        int id = sc.nextInt();
        if(id == 3 | id == 5|id == 7) {
            System.out.println("是3或者5或者7");
        }
        else {
            System.out.println("非3或5或7");
        }
    }
}

 

 

posted @ 2021-12-07 10:36  辣子杨  阅读(24)  评论(0编辑  收藏  举报