In this program, user will enter any sentence and status of each characters of the sentence - whether it is uppper case, lower case character, if it is a digit or letter or a special character will be shown by the program
import java.io.*;
class Ch
{
int i,len;
String s;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
void show() throws Exception
{
System.out.print("\nEnter the String:");
s=br.readLine();
len=s.length();
for(i=0;i< len;i++)
{
if((s.charAt(i) >=65 && s.charAt(i)<=90)||(s.charAt(i) >=97 && s.charAt(i)<=122))
{
if(Character.isUpperCase(s.charAt(i)))
if(Character.isDigit(s.charAt(i)))
System.out.println(s.charAt(i) + "::is a digit.");
if(Character.isLetter(s.charAt(i)))
System.out.println(s.charAt(i) + "::is a letter.");
if(Character.isLowerCase(s.charAt(i)))
System.out.println(s.charAt(i) + "::is a lower case letter.");
}
else
System.out.println(s.charAt(i) + "::is a special character.");
System.out.println("\n");
}
}
public static void main(String args[])throws Exception
{
Ch ob=new Ch();
ob.show();
}
}
Sample Input Output
@::is a special character.
::is a special character.
c::is a letter.
c::is a lower case letter.
h::is a letter.
h::is a lower case letter.
a::is a letter.
a::is a lower case letter.
r::is a letter.
r::is a lower case letter.
a::is a letter.
a::is a lower case letter.
c::is a letter.
c::is a lower case letter.
t::is a letter.
t::is a lower case letter.
e::is a letter.
e::is a lower case letter.
r::is a letter.
r::is a lower case letter.
s::is a letter.
s::is a lower case letter.
Related Post: BlueJ Programs on String/Sentence
No comments:
Post a Comment