Example:
Input Name: Sumanta Pramanick.
Output: S.P.
Code:
import java.util.*;
class Initials_Scanner
{
public static void main(String args[])
{
String st; int l,i; char c;
Scanner sc=new Scanner(System.in);
System.out.print("Enter any sentence: ");
st=sc.nextLine();
st=" "+st; //adding a space infront of the inputted sentence or a name
st=st.toUpperCase(); //converting the sentence into Upper Case (Capital Letters)
l=st.length(); //finding the length of the sentence</span>
for(i=0;i<l;i++)
{
c=st.charAt(i); //taking out one character at a time from the sentence
if(c==' ') //if the character is a space, printing the next Character along with a fullstop
System.out.print(st.charAt(i+1)+".");
}
}
}
Input Name: Sumanta Pramanick.
Output: S.P.
Code:
import java.util.*;
class Initials_Scanner
{
public static void main(String args[])
{
String st; int l,i; char c;
Scanner sc=new Scanner(System.in);
System.out.print("Enter any sentence: ");
st=sc.nextLine();
st=" "+st; //adding a space infront of the inputted sentence or a name
st=st.toUpperCase(); //converting the sentence into Upper Case (Capital Letters)
l=st.length(); //finding the length of the sentence</span>
for(i=0;i<l;i++)
{
c=st.charAt(i); //taking out one character at a time from the sentence
if(c==' ') //if the character is a space, printing the next Character along with a fullstop
System.out.print(st.charAt(i+1)+".");
}
}
}
No comments:
Post a Comment