Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ***************
- // * The *
- // * strangest *
- // * text *
- // * that *
- // * is *
- // * going *
- // * to *
- // * be *
- // * shown *
- // * in *
- // * a *
- // * rectangular *
- // * frame *
- // ***************
- public class TextInFrame {
- private static int getLongestStringLength(String[] array) {
- int maxLength = 0;
- for (String s : array)
- if (s.length() > maxLength)
- maxLength = s.length();
- return maxLength;
- }
- private static String repeatString(int count, String theChar) {
- return new String(new char[count]).replace("\0", theChar);
- }
- public static void main(String[] args) {
- String[] text = "The strangest text that is going to be shown in a rectangular frame".split(" ");
- int width = getLongestStringLength(text) + 4;
- String border = repeatString(width, "*");
- System.out.println(border);
- for (String item : text)
- System.out.format("* %s%s*\n", item, repeatString(width - 3 - item.length(), " "));
- System.out.println(border);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment