你能帮我这个代码吗?
非常感谢任何建议 - Newbie2Java 我有一些很好的意见 - 谢谢(缺少链接)
这是我的代码:
导入 java.util.Scanner;
公共类 Question5WIP {
/**
* @param args
public static void main(String[] args) {
// TODO Auto-generated method stub
// boolean correctInput = false; // assume we dont have correct input
// while (!correctInput){ // continue as long as not correct input
int hourValue = 0;
Scanner in;
while (!(hourValue > 0 && hourValue <= 12)) {
System. out.println("Please enter the hours (between 1 and 12): ");
in = new Scanner(System.in); // User input hour value.
hourValue = in.nextInt();
if (!(hourValue > 0 && hourValue <= 12)) {
System.out.println("Hour Value should be between 1 and 12, please try again "); // invalid hours.
}
}
int minuteValue = 0;
// Scanner in;
while (!(minuteValue > 0 && hourValue <= 60)) {
System. out.println("Please enter the minutes (between 1 and 60): ");
in = new Scanner(System.in); // User input hour value.
minuteValue = in.nextInt();
if (!(minuteValue > 0 && minuteValue <= 60)) {
System.out.println("Invalid entry, please try again: "); // invalid hours.
return;
}