I need an int value for both inputs. Either the user write 1 or 01 for january. So it does work for 1 - 12 but if I write 01 it does give me my own error Text. For me its importend that it is a int Value, I know that String is perfectly work.
private static BufferedReader input= new BufferedReader(new InputStreamReader(System.in));
private Output output = new Output();
public static String inputText() throws Exception {
return input.readLine();
}
public int monatInput(String text){
String monthNumber= "";
boolean again = true;
while (again) {
System.out.print(text);
again = false;
try {
monthNumber = inputText();
int number= Integer.parseInt(monatZahl);
int monthLength = String.valueOf(monatZahl).length();
if (number<=1 || number>=12) {
again = true;
throw new Exception();
} else if (monthLength> 3) {
again = true;
throw new Exception();
}
} catch (Exception e) {
this.output.monatWrongInput;
}
}
int converter = Integer.parseInt(monatZahl);
return converter;
}
I hope you guys can help me to validate this problem. I seen many post about a for-loop to generate 01 digit but thats a bit different then validate as user input. Sorry for my bad english. Best regard MonsterHunter.Dev
Aucun commentaire:
Enregistrer un commentaire