one if statement returns none

by Gao Gao   Last Updated June 13, 2019 08:26 AM

one if statement should return a string, however it turns out none.

I have tried to set a String variable output to store the expected string in the if statement.

public static String starString(int n){

if(n<0){
   String output = "";
   return output = "IllegalArgumentException";
}else{
    String stars = "";
    for(int i = 0; i < Math.pow(2, n); i++){
        stars += "*";
    }
      return stars;
}

}

I expect starString(-1) exp. exception:IllegalArgumentException

the error message: none

Tags : java recursion


Related Questions


Updated September 09, 2017 03:26 AM

Updated November 23, 2018 14:26 PM

Updated April 21, 2015 04:11 AM

Updated May 01, 2019 18:26 PM

Updated January 19, 2018 03:26 AM