Ad

Complete the method wich accepts value, and return a String like following example:

  • If the value is positive, you display the result like this example:

    • The value is 3, the result will be: "1-22-333"
    • The value is 5, the result will be: "1-22-333-4444-55555"
  • If the value is negative, you display the result like this example:

    • The value is -3, the result will be: "1+22+333"
    • The value is -5, the result will be: "1+22+333+4444+55555"
class Solution {
  public static String numberOfNumbers(int value) {
    StringBuilder finalWord = new StringBuilder();
		int j = 0;
		String sign = value < 0 ? "+" : "-";

		if (value == 0) return "";
		
		if (value < 0) value *=-1;

		for (int i = 1; i <= value; ++i) {
			j = i;
			while (j > 0) {
				finalWord.append(i);
				--j;
			}
			finalWord.append(sign);
		}

		return finalWord.deleteCharAt(finalWord.length() - 1).toString();
  }
}