Write a program in java to accept a sentence and print only the first letter of each word of the sentence in capital letters separated by a full stop.
Example:
INPUT SENTENCE = "This is a cat."
OUTPUT SENTENCE = T.I.A.C.
Answers
Answered by
3
Here Is Your Answer:
import java.util.*;
class ShortForm
{
public static void main(String[]args)
{
String str;
char ch;
int i,pos=0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter The Sentence");
str = sc.nextLine();
str = " "+str;
for(i=0;i<str.length();i++)
{
ch = str.charAt(i);
if(ch == ' ')
{
System.out.print(Character.toUpperCase(str.charAt(i+1)) +".");
}
}
}
}
Similar questions