String multiply(String s) - returns a string repeated 5 times.

String multiply(String s, int count) - returns a string repeated count times.

 public static String multiply(String s) { String result = ""; int res = Integer.parseInt(result); res = 0; while(res <= 5){ res++; } return result; } public static String multiply(String s, int count) { String result = ""; int res = Integer.parseInt(result); res *= count; return result; } public static void main(String[] args) { System.out.println(multiply("string")); } 
  • I dare to suggest that System.out.print does not print anything because it is not in the code? - Maxim
  • Not present at the moment. But he is not needed here. Just when I wrote it, he did not deduce anything as if he was not there. The main task is to return the rows. - AlexeyVL
  • 2
    In the method, you create the variable String result = ""; then you do NOTHING with it and return it :) but you ignore the variable transmitted to the input altogether) well, in general, the lines in java are immutable, therefore there must be something else in the return . Think what exactly. - learp

1 answer 1

Well, something like this:

  public static String multiply(String s, int count) { String result = ""; for(int i = 0; i < count; i++) result += s; return result; } public static String multiply(String s) { return multiply(s, 5); } 
  • Super! I'm a sucker: ((When I start to figure it out))) - AlexeyVL