This method is supposed to check if the inputed number is a number and not a letter and then complete the function. However, every time I try it always is saying the input is wrong.
For example:
If I type in "5 * 5"
it says Error Incorrect Input
Re-input your numbers:
when it shouldn't do anything. I can't figure it out.
My Code Is:
public void multiply() throws IOException { boolean valid = true; boolean valid1 = true; int i = 0; int k = 0; String string = input; String[] strings = string.split("\\*"); String string1 = strings[0]; String string2 = strings[1]; for (valid = true; i < strings[0].length();) { if (strings[0].charAt(i) == '0' || strings[0].charAt(i) == '1' || strings[0].charAt(i) == '2' || strings[0].charAt(i) == '3' || strings[0].charAt(i) == '4' || strings[0].charAt(i) == '5' || strings[0].charAt(i) == '6' || strings[0].charAt(i) == '7' || strings[0].charAt(i) == '8' || strings[0].charAt(i) == '9' || strings[0].charAt(i) == '*') { valid = true; } else { valid = false; } i++; } for (valid1 = true; k < strings[1].length();) { if (strings[1].charAt(k) == '0' || strings[1].charAt(k) == '1' || strings[1].charAt(k) == '2' || strings[1].charAt(k) == '3' || strings[1].charAt(k) == '4' || strings[1].charAt(k) == '5' || strings[1].charAt(k) == '6' || strings[1].charAt(k) == '7' || strings[1].charAt(k) == '8' || strings[1].charAt(k) == '9' || strings[1].charAt(k) == '*') { valid1 = true; } else { valid1 = false; } k++; if (valid1 == true && valid == true) { System.out.println("Multiply"); //Going to finish } else { System.out.println("Error Incorrect Input"); System.out.println("Re-input your numbers:"); check(); } } }