-
Problem...
import java.util.*;
public class SentenceSplit
{
public static void main (String[] args)
{
Scanner in = new Scanner (System.in);
String userInput;
String output;
int stringsize;
System.out.println("Enter a sentence");
userInput = in.nextLine();
stringsize = userInput.length();
output = userInput.substring(stringsize/2);
System.out.println(output);
}
}
That is my program, and it works fine and everything...but what would i need to do in order for each letter of the sentence to go on its own line?
ie. H
e
l
l
o
-
Something like this should work.
Code:
for(int i = 0; i <= stringSize; i++)
{
System.out.println(userInput.indexOf(i,i));
}
I didn't test it but that should be the right idea.
-
well i don't know if u like this, u can use charAt()
u got to form the loop
Code:
for (int i = 0; i<stringsize; i++) {
System.out.println(userInput.charAt(i) + "\n");
}
this way it will read the char from the string by the location and then output it to the command prompt and the \n is for next line