Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » Homework HelpRSS Feeds

Program to show the use of some Character Methods

Posted By: Benjamin Smith     Category: Java     Views: 2166

A Java Program to show the use of some Character Methods.

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");
    }
 }
  
Share: 


Didn't find what you were looking for? Find more on Program to show the use of some Character Methods Or get search suggestion and latest updates.

Benjamin Smith
Benjamin Smith author of Program to show the use of some Character Methods is from Sydney, Australia.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!