Printing a string of text into multiple lines? Java -
i using scanner utility read sentence inputted keyboard. want know how able transform string text multiple lines..
so example, if enter
"how doing?" (two spaces between , doing)
how able create print onto multiple lines?
how doing?
solved using system.out.println(str.replace(" ", "\n"))
thanks all.
try below code
public static void main(string[] args) { scanner = new scanner(system.in); string lines = a.nextline(); boolean emptyline = true; (string line : lines.split(" ")) { if (!"".equals(line.trim())) { system.out.println(line); emptyline = true; } else if (emptyline) { system.out.println(); emptyline = false; } } }
java
No comments:
Post a Comment