Question 6
Write a program 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 : T.I.A.C
Use java
Answers
Answered by
41
U could just change it to upper case....
Attachments:
Answered by
28
Sample program to accept and print first letter of each word:
import java.util.*;
class Brainly
{
public static void main(String args[])
{
String str, strDemo,s;
Scanner demo = new Scanner(System.in);
System.out.println("Enter a sentence: ");
str = demo.nextLine();
Scanner scan = new Scanner(str);
strDemo = "";
while(scan.hasNext())
{
s = scan.next();
strDemo = strDemo + s.substring(0, 1).toUpperCase() + ".";
}
System.out.println("After capitalizing : " + strDemo);
}
}
Output:
Enter a sentence:
this is a cat
After capitalizing: T.I.A.C
Hope it helps!
Attachments:
Similar questions