gpt4 book ai didi

java - 如何检查java中的int范围并将其限制为仅5位数字

转载 作者:行者123 更新时间:2023-12-01 19:16:33 25 4
gpt4 key购买 nike

请帮我完成作业。问题如下:

Create a separate test driver class called TestEmployeePayroll that will test the EmployeePayroll class by performing the following:

Prompt the user to enter the employees’ ID number, First name, Last name, Pay Category and Hours worked (one at a time).

  • The user entry for employees ID number must be exactly 5 digits long.
  • The user entry for Category must only be accepted if it is in the range 1 to 4.
  • The user entry for Hours worked must only be accepted if it is the range 1 to 80.

这就是我到目前为止所做的:

import java.util.Scanner;
public class TestEmployeePayRoll {

public static void main(String[] args){
EmployeePayRoll obj1 = new EmployeePayRoll();

Scanner input = new Scanner(System.in);
System.out.println("Enter the Employee ID number: "+ " ");
String EmployeeID = input.nextLine();

//How to check the range here if int is 5 digits long or not ?

System.out.println("Enter the first Name: "+ " ");
String FirstName = input.nextLine();

System.out.println("Enter Last Name: "+ " ");
String LastName = input.nextLine();

System.out.println("Enter the Pay Category: "+ " ");
double PayCategory = input.nextDouble();

System.out.println("Enter the number of hours worked: "+ " ");
double HoursWorked = input.nextDouble();
}
}

最佳答案

您可能想要使用Integer.parseInt() .

关于java - 如何检查java中的int范围并将其限制为仅5位数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6395574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com