Q:

My method needs to return a string, what am i doing wrong?

My program is complaining that the method is not returning a string. What am I doing wrong with my return statement? Thanks
 public String diskGame( int n)
 {   
     char fromPole = 'A';
     char toPole = 'B';

     //base case
     if (n == 1)  //there is only 1 disk left
     {
        return( "Move White from " + fromPole + " to " + toPole + "/n");

     }
 }

A:

Your return statement is in an IF which is an issue.
IF n is not equal to 1 the program will not reach return statement and hence the error.
Add a return statement
     public String diskGame( int n)
     {   
         char fromPole = 'A';
         char toPole = 'B';
         String result = "";

         //base case
         if (n == 1)  //there is only 1 disk left
         {
           result = "Move White from " + fromPole + " to " + toPole + "/n"

         }
       return result;
     }

Obviously you can set the default value of result to anything you want.In case, n!=1 it will return "" in my code, add anything you want for user understanding, don't leave it blank

