public class Kata { public static String createPhoneNumber(int[] numbers) { public int Int_to_str(int i) { return Integer.toString(numbers[i]); } return "(" + Int_to_str(0) + Int_to_str(1) + Int_to_str(2) + ") " + Int_to_str(3) + Int_to_str(4) + Int_to_str(5) + "-" + Int_to_str(6) + Int_to_str(7) + Int_to_str(8) + Int_to_str(9); } } 

Returns an error:

 public int Int_to_str(int i){ ^ /Kata.java:3: error: ';' expected public int Int_to_str(int i){ ^ /Kata.java:3: error: ';' expected public int Int_to_str(int i){ 
  • four
    Are you confused by the method in the method? - post_zeew

1 answer 1

You have a method in a method. Take it out and make it static .

For example:

 public class Kata { private static int[] numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; public static String createPhoneNumber(int[] numbers) { return "(" + Int_to_str(0) + Int_to_str(1) + Int_to_str(2) + ") " + Int_to_str(3) + Int_to_str(4) + Int_to_str(5) + "-" + Int_to_str(6) + Int_to_str(7) + Int_to_str(8) + Int_to_str(9); } public static String Int_to_str(int i) { return Integer.toString(numbers[i]); } public static void main(String args[]) { System.out.println(createPhoneNumber(numbers)); } } 

Excess can be removed leaving only methods. The code can be rewritten much better, but it also works.