The logic is to store every letter after " "[ <blankspace>||whitespace hence adding a space to the INPUT sentence ]
We use charAt() function to get each character of the input sentence and then we check for the space using the if-statement
then storing the letter program as follows
import java.io.*; class FirstLetter { public static void main(String args[])throws IOException { DataInputStream ak = new DataInputStream(System.in);
String str; char y; int lengt;
System.out.print("Enter any sentence: "); str = ak.readLine();
//adding a space in front of the input sentence str = " " + str; str = str.toUpperCase();
//finding the length of the input sentence lengt = str.length();
System.out.print("Output = "); for(int i=0;i<lengt;i++) { //taking out one character at a time from the sentence y = str.charAt(i); if(y==' ') { System.out.print(str.charAt(i+1)+"."); } } } }
Answers & Comments
Verified answer
Heya friend,The logic is to store every letter after " "[ <blankspace>||whitespace
hence adding a space to the INPUT sentence ]
We use charAt() function to get each character of the input sentence
and then we check for the space using the if-statement
then storing the letter
program as follows
import java.io.*;
class FirstLetter
{
public static void main(String args[])throws IOException
{
DataInputStream ak = new DataInputStream(System.in);
String str;
char y;
int lengt;
System.out.print("Enter any sentence: ");
str = ak.readLine();
//adding a space in front of the input sentence
str = " " + str;
str = str.toUpperCase();
//finding the length of the input sentence
lengt = str.length();
System.out.print("Output = ");
for(int i=0;i<lengt;i++)
{
//taking out one character at a time from the sentence
y = str.charAt(i);
if(y==' ')
{
System.out.print(str.charAt(i+1)+".");
}
}
}
}
HOPE THIS HELPS!!!!!!!!