Computer Applications
Write a program in java to accept a string and display the new string after reversing the characters of each word and converting first letter of each word to upper case.
Sample Input:
the tea is hot
Sample Output:
ehT aeT sI toH
Java
Java String Handling
15 Likes
Answer
import java.util.Scanner;
public class KboatStringReverseWord
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter the sentence: ");
String str = in.nextLine();
str = str + " ";
String word = "";
int len = str.length();
for (int i = 0; i < len; i++) {
char ch = str.charAt(i);
if (ch == ' ') {
int x = word.length();
for (int j = x - 1; j >= 0; j--) {
char ch2 = word.charAt(j);
if (j == 0) {
System.out.print(Character.toUpperCase(ch2));
}
else {
System.out.print(ch2);
}
}
System.out.print(" ");
word = "";
}
else {
word += ch;
}
}
}
}Output

Answered By
4 Likes
Related Questions
Write a Java program to enter any sentence and convert the sentence to uppercase. Print only those words of the sentence whose first and last letters are the same.
Which of the following returns a String?
- length()
- charAt(int)
- replace(char, char)
- indexOf(String)
Define a class to accept the gmail id and check for its validity.
A gmail id is valid only if it has:
→ @
→ .(dot)
→ gmail
→ com
Example:
icse2024@gmail.comis a valid gmail id