Home > Java > javaTutorial > How to use Java to implement exam rewards?

How to use Java to implement exam rewards?

WBOY
Release: 2023-04-23 15:10:16
forward
1150 people have browsed it

Exam Rewards

1. Question:

It’s almost the final exam. Xiao Ming’s father said that he will give him different gifts based on Xiao Ming’s scores. If you can control Xiao Ming’s score, Please use the program to realize what kind of gift Xiao Ming should get.

2. Analysis:

  • Xiao Ming’s test score is unknown, and the value can be obtained by keyboard entry (needs to import packages, create objects, and receive data);

  • Because there are many types of rewards, they belong to multiple judgments, which are implemented in the if...else...if format;

  • Set corresponding conditions for each judgment ;

  • Set corresponding rewards for each judgment.

3. Practice:

The code is as follows (example):

public class Demo3 {
    public static void main(String[] args) {
    //不爱生姜不吃醋
        //小明的考试成绩未知,可以采用键盘录入的方式获取值
        //(需要导包import java.util.Scanner;,创建对象,接收数据)
        Scanner sc=new Scanner(System.in);

        System.out.println("请输入一个分数:");
        int score = sc.nextInt();
        //由于奖励种类较多,属于多种判断,采用if...else...if格式实现;
        //为每种判断设置对应的条件;
        //为每种判断设置对应的奖励。
        if(score >= 95 && score <= 100){
            System.out.println("游乐场一日游!");
        }else if(score < 95 && score >=85){
            System.out.println("迪迦奥特曼玩具!");
        }else if(score < 85 && score >= 70){
            System.out.println("什么都不送!");
        }else{
            System.out.println("男女混合双打!");
        }
        
        //数据边界
        if(score>100 | score <0){
            System.out.println("你输入的分数有误!");
        }
    }
}
Copy after login

The above is the detailed content of How to use Java to implement exam rewards?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template