【发布时间】:2021-05-13 11:00:01
【问题描述】:
基本上,我需要返回正确的年份,即 2022 年以上。我需要返回它,以便其他方法可以访问它。如果用户不输入,这应该是一个循环提示错误。
Scanner input = new Scanner(System.in);
boolean good = false;
do
{
System.out.println("Enter the expiration year:");
int userYear = Integer.parseInt(input.nextLine());
if(userYear > 2022)
good = true;
else
System.out.println("Invalid. Try again.");
int userYears = Integer.parseInt(input.nextLine());
}
while (!good);
good = false;
// return userYear;
我想回到这里,以便我的其他方法可以看到。
【问题讨论】:
标签: java eclipse loops return do-while