Reputation: 11
Enter a line of text. No punctuation please.
Java is the language.
I have rephrased that line to read:
Is the language java.
Attempt:
int x;
String sentence, first;
System.out.println("\nEnter a line of text. No punctuation please.");
Scanner keyboard = new Scanner (System.in);
sentence=keyboard.nextLine();
x = sentence.indexOf(" ");
first= sentence.substring(0,x);
second=sentence.substring(0,1)
second=second.toUpperCase();
System.out.println("I have rephrased that line to read:");
System.out.println(second+sentence.substring(x+1)+" "+first);
Output:
Enter a line of text. No punctuation please.
what is going on
I have rephrased that line to read:// It should read " Is going on what"
W s going on what
P.S -I need to make letter "i" capital. How can I make "second.substring(0,1)" read character "i"? As suggested, I tried to figure out the stripping the letter and concatenating it with the uppercase but I am not sure.
Upvotes: 1
Views: 430
Reputation: 81104
The "i" would be
second=sentence.substring(x+1,x+2);
In other words, the character after the space. You're currently taking the first character in the input string.
Upvotes: 1