Write code to set String Length to shorten string
//package com.book2s; public class Main { public static void main(String[] argv) { String s = "book2s.com"; int howLong = 42; System.out.println(setStringLength(s, howLong)); }/* ww w . j a va 2s . c o m*/ public static String setStringLength(String s, int howLong) { String result; if (s.length() > howLong) { result = s.substring(0, howLong - 3) + "..."; } else if (s.length() == howLong) { result = s; } else { result = createSpaces(howLong - s.length()); result += s; } return result; } public static String createSpaces(int howMany) { String result = ""; for (int n = 0; n < howMany; n++) { result += " "; } return result; } }