Results 1 to 3 of 3
Thread: Problem...
- 11-08-2007, 09:05 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 19
- Rep Power
- 0
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
- 11-08-2007, 09:47 PM #2
Something like this should work.
I didn't test it but that should be the right idea.Java Code:for(int i = 0; i <= stringSize; i++) { System.out.println(userInput.indexOf(i,i)); }
- 11-12-2007, 07:26 AM #3
Member
- Join Date
- Oct 2007
- Posts
- 21
- Rep Power
- 0
well i don't know if u like this, u can use charAt()
u got to form the loop
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 lineJava Code:for (int i = 0; i<stringsize; i++) { System.out.println(userInput.charAt(i) + "\n"); }


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks