Code for Program to show the use of some Character Methods in Java
publicclass JAVA_026
{
publicstaticvoid main(String[] args)
{
char Symbol=(char)(Math.random( )*128);
if(Character.isLetterOrDigit(Symbol))
{
if(Character.isDigit(Symbol))
System.out.println("The Random Generated ASCII Code is a Digit (0-9) : " + Symbol);
elseif(Character.isLetter(Symbol))
{
if(Character.isUpperCase(Symbol))
System.out.println("The Random Generated ASCII Code is a Capital Letter (A-Z) : " + Symbol);
elseif(Character.isLowerCase(Symbol))
System.out.println("The Random Generated ASCII Code is a Lower Letter (a-z) : " + Symbol);
}
}
elseif(Character.isWhitespace(Symbol))
{
System.out.println("The Random Generated ASCII Code is a White Space (' ','\\t','\\n','\\r','\\f') : "+(int)(Symbol));
switch(Symbol)
{
case' ' : System.out.println("Space (' ')");
break;
case'\t' : System.out.println("Tab ('\\t')");
break;
case'\n' : System.out.println("NewLine ('\\n')");
break;
case'\r' : System.out.println("Carriage Return ('\\r')");
break;
case'\f' : System.out.println("Line Feed ('\\f')");
break;
default : System.out.println("Cannot be Displayed");
}
}
else
System.out.println("The Random Generated ASCII Code is Not a Letter or Digit or Whitespace");
}
}