private String convert(String[] words, int start, int end, int L) {
		StringBuilder sb = new StringBuilder();

		// if this line only contains one word
		if (start == end) {
			sb.append(words[start]);
			for (int i = 0; i < L - words[start].length(); i++) {
				sb.append(" ");
			}
			return sb.toString();
		}
		// if the line is the last line, the space distribution rule is
		// different
		else if (end == words.length - 1) {
			int curLen = 0;
			for (int i = start; i < end; i++) {
				sb.append(words[i]);
				sb.append(" ");
				curLen += words[i].length() + 1;
			}
			sb.append(words[end]);
			curLen += words[end].length();

			for (int i = 0; i < L - curLen; i++) {
				sb.append(" ");
			}
			return sb.toString();
		}

		// calculate the lengths of padding space
		int totalLen = 0, numOfSpaces = end - start;
		for (int i = start; i <= end; i++)
			totalLen += words[i].length();
		int lenOfPaddingSpace = (L - totalLen) / numOfSpaces;
		int numOfExtraSpaces = (L - totalLen) % numOfSpaces;

		// construct the line
		int count = 0; // count of the extra spaces
		for (int i = start; i < end; i++) {
			sb.append(words[i]);
			for (int j = 0; j < lenOfPaddingSpace; j++)
				sb.append(" ");
			if (count < numOfExtraSpaces)
				sb.append(" ");
			count++;
		}
		sb.append(words[end]);

		return sb.toString();
	}