I have this problem in java. When I write 3/5 + 3 it returns 18/5 and it's correct but if I write 3/5/ + 3 it returns 18/5 instead of error
public static RatNum parse(String s) {
int x = 0;
int y = 0;
String split[] = s.split("/");
if (split.length == 2) {
x = Integer.parseInt(split[0]);
y = Integer.parseInt(split[1]);
return new RatNum(x, y);
} else if (split.length == 1) {
x = Integer.parseInt(s);
return new RatNum(x);
} else {
throw new NumberFormatException("Error");
}
}