I'm fairly new to java and trying to make a roman numeral calculator. I have the main coding done but I want to add the ability to check for "illegal" characters in the main string.
I have created a method called "ValidCheck" to test all chars in the string against a list of acceptable characters.
public static boolean ValidCheck(String letter){
boolean okay = true;
for (int i = 0; i < Letters.length; i++){
if (Letters[i] != letter){
okay = false;
}
}
return okay;
}
Here is the input from the user. I want to be able to print an error message and then just repeat the original question until the string is acceptable and ValidCheck == true
.
System.out.print("Type in a Roman Numeral value: ");
String roman = kb.next();
for (int i = 0; i < roman.length(); i++){
if (ValidCheck(roman.charAt(i) + "") == false){
System.out.println("Error with input. Unexpected character.");
}
}
ex.
Type in a Roman Numeral : MMDK
Error with input. Unexpected character.
Type in a Roman Numeral :
I'm wondering how I can put this into a loop to ask repeatedly until the input is deemed acceptable using the method? Also since I'm fairly new an explanation of how it is repeating and how the value is returned from the loop would be greatly appreciated!