C Programs Tutorials | IT Developer
IT Developer

Java Programs



Share with a Friend

Abbreviation Program - Java Programs

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: This is a cat.
OUTPUT: T.I.A.C.

import java.io.*; class Sentence{ public static void main(String args[])throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter the sentence: "); String s = br.readLine(); s = s.trim(); s = s.toUpperCase(); String t = ""; for(int i = 0; i < s.length(); i++){ if(i == 0 || s.charAt(i - 1) == ' ') t += s.charAt(i) + "."; } System.out.println(t); } }

Output

 
 OUTPUT : 
Enter the sentence: This is a cat.
T.I.A.C.