Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. public static void wordWrap3 (Scanner input) {
  2. while (input.hasNextLine()) {
  3. String currentLine = input.nextLine();
  4. String wordSum = "";
  5. String currentWord = "";
  6. int lineLength = currentLine.length();
  7. int lineSum = 0;
  8. if (lineLength <= 60) {
  9. System.out.println(currentLine);
  10. } else {
  11. while (lineSum <= 60) {
  12. currentWord = input.next();
  13. if (currentWord.equals(" ")) {
  14. lineSum++;
  15. } else {
  16. wordSum = wordSum + " " + currentWord;
  17. lineSum = lineSum + currentWord.length();
  18. }
  19. }
  20. System.out.println(wordSum);
  21. }
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement