私はJavaを使い慣れていないため、ユーザー入力をどのように検証するのか把握しようとしています。ユーザーが800より低い数値または1900より高い数値を入力すると、適切なエラーメッセージが表示されます。私はまた、860などの時間を入力すると、ユーザーにエラーメッセージが表示されるようにしたい...私はこの部分の周りに巻き込まれてきたので、間違いなく助けが必要です。は時間を有効にする必要がありますが、問題は継続して実行する必要があります
import java.util.Scanner;
public class FugonIsaac06 {
public static void main(String[] args) {
boolean keepAsking = true;
Scanner reader = new Scanner(System.in);
String userInput = "";
int input_Start = 0;
int input_End = 0;
while (keepAsking) {
System.out.print("Please enter your name: ");
userInput = reader.nextLine();
if (userInput.length() >= 3) {
keepAsking = false;
} else {
System.out.println("Name must be at least 3 characters long.");
}
}
keepAsking = true;
//You will need to somehow separate the hours and minutes from the input.
//Use integer division and modulus to separate hours and minutes.
//Hours = Input/100
//Minutes = Input % 100
//To convert the minutes to parts of an hour divide the minutes by 60.0.
//Parts of an hour = Minutes/60.0
int hours_Start = input_Start/100;
int minutes_Start = input_Start % 100;
while (keepAsking) {
System.out.print("Enter start time: ");
input_Start = reader.nextInt();
if ((input_Start > hours_Start) &&
(input_Start < minutes_Start)) {
keepAsking = true;
System.out.println("Start time should be between 800 and 1900");
} else {
System.out.println("Time is malformed, minutes should be between 0 and 59");
}
}
}
}
それを試してみてください?別のdoループを使用しますか?また、助けてくれてありがとう。 – ike626
@ ike626私は自分の答えを更新しました。 –