this is the code that has error ..
"missing return statement"
it WAS like this , and it doesnt have any errors such like thatpublic static boolean ToDecimalCont() throws IOException { String keyIn; System.out.println(""); System.out.print("Do You Want To Change The Numerical Type?: "); keyIn = br.readLine(); if ((keyIn.equalsIgnoreCase("Y")) || (keyIn.equalsIgnoreCase("YES"))) { return true; } else if ((keyIn.equalsIgnoreCase("N")) || (keyIn.equalsIgnoreCase("NO"))) { return false; } else if ((keyIn.equalsIgnoreCase("exit")) || (keyIn.equalsIgnoreCase("quit"))) { System.exit(0); //but when i add return false or true; it compiles fine. } else { return false; } }
i've notice that IN THE FIRST CODE when I added another elseIf statement (the third one with System.exit(0)), the compiler is asking for a return statement... WHICH I ALREADY HAVE on the default part which is 'else',public static boolean ToDecimalCont() throws IOException { String keyIn; System.out.println(""); System.out.print("Do You Want To Change The Numerical Type?: "); keyIn = br.readLine(); if ((keyIn.equalsIgnoreCase("Y")) || (keyIn.equalsIgnoreCase("YES"))) { return true; } else if ((keyIn.equalsIgnoreCase("N")) || (keyIn.equalsIgnoreCase("NO"))) { return false; } else { return false; } }
and regarding with the FIRST CODE' ,the THE THIRD BRANCH OF IF (the elseIf that has a System.exit(0);, when i add this after the System.exit(0);, it compiles prefectly..return false or true;
questions:
1.) why is the compiler asks me to define a return value? (when i already have the default or the else block)
2.) is this somewhat kind of unreachable statement?
need some clarification..