Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void wordWrap3 (Scanner input) {
- while (input.hasNextLine()) {
- String currentLine = input.nextLine();
- String wordSum = "";
- String currentWord = "";
- int lineLength = currentLine.length();
- int lineSum = 0;
- if (lineLength <= 60) {
- System.out.println(currentLine);
- } else {
- while (lineSum <= 60) {
- currentWord = input.next();
- if (currentWord.equals(" ")) {
- lineSum++;
- } else {
- wordSum = wordSum + " " + currentWord;
- lineSum = lineSum + currentWord.length();
- }
- }
- System.out.println(wordSum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement