zoukankan      html  css  js  c++  java
  • if语句基本练习需求

    1.需求:键盘录入一个成绩,判断并输出成绩的等级。
    90-100 优
    80-89  良好
    70-79  中等
    60-69  及格
    0-59   不及格
    import java.util.Scanner;
    class Hello2 {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入学生成绩范围在0-100之间");
            int x = sc.nextInt();
            if (x >= 90 && x <=100) {
                System.out.println("优");
            }else if (x >=80 && x <= 89)
            {
                System.out.println("良好");
            }else if (x >=70 && x <= 79)
            {
                System.out.println("中等");
            }else if (x >=60 && x <= 69)
            {
                System.out.println("及格");
            }else {
                System.out.println("不及格");
                }
        }
    }

    结果:

    2:需求:

    • 键盘录入x的值,计算出y的并输出。

    • x>=3 y = 2 * x + 1;

    • -1<x<3 y = 2 * x;
    • x<=-1 y = 2 * x - 1;
    import java.util.Scanner;
    class Hello2 {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入一个整数");
            int x = sc.nextInt();
            int y = 0;
            if (x >= 3) {
                y = 2 * x + 1;
            }else if (x > -1 && x < 3)
            {
                y = 2 * x;
            }else if (x <= -1)
            {
                y = 2 * x - 1;
            }
            System.out.println("y = " + y);
        }
    }

    结果:

     

     
  • 相关阅读:
    oracle锁分类
    oracle中decode函数
    oracle分区
    oracle处理字符串
    oracle索引分类
    oracle表连接
    oracle处理字符串
    oracle分区
    木马中如何编程实现远程关机
    木马中如何编程实现远程关机
  • 原文地址:https://www.cnblogs.com/Wangzui1127/p/11152734.html
Copyright © 2011-2022 走看看