JAVA学习(年薪计算器)

要求: 制作一个年薪计算器;
 * (1)通过键盘输入用户的月薪、每年是几个月薪水。
 * (2)输出用户的年薪;
 * (3)输出一行字“如果年薪超过10万,恭喜你超越90%的国人”,“如果年薪超过20万,恭喜你超越98%的国人”。
 * (4)直到键盘输入数字88,则退出程序(使用break退出循环);键盘输入66,直接显示“重新开始计算...”,然后算下一个用户的年薪。同时,对用户输入的命令进行检查,如果不是66、88则要求重新输入。
import java.util.Scanner;
public class SalaryCalculator {
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        System.out.println("**********年薪计算器**********");
        System.out.println("1.输入88退出程序;\n2.输入66,计算下一个年薪;");

        while(true){
            System.out.print("输入月薪:");
            int monthSalary=s.nextInt();
            System.out.print("输入一年可以获得多少个月工资:");
            int months=s.nextInt();
            int yearSalary=monthSalary*months; //计算年薪

            //根据年薪做出提示,使用If判断;
            System.out.print("您的年薪是:"+yearSalary+",");
            if (yearSalary>=200000){
                System.out.println("恭喜你超越98%的国人!");
            }else if (yearSalary>100000) {
                System.out.println("恭喜你超越90%的国人!");
            }else{
                System.out.println("您需要继续努力了!");
            }
            System.out.println("**************"); //为了美观设置一条装饰线
            System.out.println("1.输入88退出程序;2.输入66,计算下一个年薪;");


            int comm=s.nextInt();
            //对输入的命令进行检查,如果不是66/88则进行重新输入。
            while (comm!=66&comm!=88){
                System.out.println("命令输错误,请重新输入:");
                comm=s.nextInt();
            }

            if (comm==88){
                System.out.println("系统退出。");
                break;
            }else if (comm==66) {
                System.out.println("****计算下一个年息*****");
                continue;
            }

        }
    }
}

 

Guess you like

Origin blog.csdn.net/weixin_47401101/article/details/133442474