-3
package hollyhw;

import java.util.Random;
import java.io.*;

public class HollyHW {
    public static int censor(String chars){

I tried implementing the following. However, I did not manage.

        int letters = chars.length();
        int newLetters = letters;

        return newLetters;   
    }

Note that for this specific task, I cannot edit the void main.

    public static void main(String[] args) {
        String c1 = censor("short"); //IDE is suggesting to change to int.
        String c2 = censor("longer the short"); //IDE is suggesting to change to int.
        String c3 = censor("the longest one we've got"); //IDE is suggesting to change to int.

        print(c1);
        print(c2);
        print(c3);
        print("");
    }
}
Robert
  • 50
  • 1
  • 3
  • 10
  • you want to *convert* the `int` to a `String`?! Shortest way `return "" + newLetters;` + change the return type of the method. – luk2302 Jan 15 '17 at 16:27
  • Possible duplicate of [How do I convert from int to String?](http://stackoverflow.com/questions/4105331/how-do-i-convert-from-int-to-string) – Ole V.V. Jan 15 '17 at 16:49

1 Answers1

1

You can do it like this:

public static String lengthAsString(String str) {
    int len = str.length();
    return Integer.toString(len);   
}
thegauravmahawar
  • 2,802
  • 3
  • 14
  • 23