0

It says "int addition = t+r;" is an unreachable statement. what does that mean? How to correct it?

public class parseMETHOD {
       public static void main(String[] args) {
           int a=9;
           int b=45;
           int result=calFunction(a,b);
           System.out.println(result);
       }

       private static int calFunction(int t,int r) {
           throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools |
   Templates.
           int addition = t+r;
           return addition;

       } }
ymonad
  • 11,710
  • 1
  • 38
  • 49
  • in `calFunction()` you throw an error right at the beginning of the function, so the following statements are never going to be called, i.e. they can't be reached. You can add a conditional check before throwing the error, so that the following statements could potentially be reached. – Jayce444 Apr 18 '18 at 03:43
  • Nothing is executed after a return ,throw statements. – Juliyanage Silva Apr 18 '18 at 04:32

1 Answers1

0

The statement is logically unreachable due to some your program's control flow. You are throwing an exception that isn't caught within your function.

Please delete the throw statement and the word "Template"

   public class parseMETHOD {
       public static void main(String[] args) {
           int a=9;
           int b=45;
           int result=calFunction(a,b);
           System.out.println(result);
       }

       private static int calFunction(int t,int r) {

           int addition = t+r;
           return addition;

       }
   }

Also, good naming conventions state that you should capitalize class names.