The assignment: prettyPrint: takes a String and an int and does not return anything. The method prints
Question:
The assignment:
prettyPrint: takes a String and an int and does not return anything. The method prints the String to the screen (using System.out.println) so that each line is exactly int characters wide, the left most character and the right most characters are not whitespace, and if needed extra spaces are added evenly between words in each line (with the later pairs of words getting the additional space when an unequal number of spaces must be added between pairs). The only exception is in the case where a line contains a single word: that word it is printed without extra spaces added.
What I should get:
HW2.prettyPrint("This homework is demonstrating how word processors make the text in a document line up so neatly.", 25) This homework is demonstrating how word processors make the text in a document line up so neatly. HW2.prettyPrint("This homework is demonstrating how word processors make the text in a document line up so neatly.", 22) This homework is demonstrating how word processors make the text in a document line up so neatly. HW2.prettyPrint("This homework is demonstrating how word processors make the text in a document line up so neatly.", 12) This homework is demonstrating how word processors make the text in a document line up so neatly.
I'm not getting anything when I input it other than a blank line
My Code:
public static void prettyPrint(String s, int x){ int numberWords = countWords(s); StringBuilder builder = new StringBuilder(); for(int i = 0; i < s.length(); i++){ if(i <= x){ padString(s, x); builder.append(s.charAt(i)); } if(i == x){ System.out.println(); } } System.out.println(); } }