Question: Java Eclipse The below code prints out each letter on a different line. I need it to print out each WORD on a different line.
Java Eclipse
The below code prints out each letter on a different line.
I need it to print out each WORD on a different line.
for instance, if the input is bob the builder i need it to print out
bob
the
builder
import java.util.*;
public class CommandLine {
public static void main(String[] args) {
String words2 ;
Scanner input = new Scanner(System.in);
words2= input.nextLine();
int i,j;
for (i=0; i <= words2.length() -1; i++) {
if (words2.substring(i).startsWith("") || i ==0){
for (j = i + 0; j <= words2.length(); j++){
if(words2.substring(j).startsWith("") || j == words2.length())
{ System.out.println(words2.substring(i,j));
i = j;
input.close();
}
}
}
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
