Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  


Shop
Java All : Character Handling
Concept Learning Code Sheets

Character Storage as a Number #3520

Demonstration of how a character is also stored like a number only.

class CharStorage
{
public static void main(String[] args)
{
char a='A';
char b=65;
if(a==b) System.out.println("characters are stored as equivalent ascii code only");
}
}

Character and Integer Inter-conversion by implicit and explicit type casting #3522

Demonstration of how a character and integer can be inter-converted by implicit and explicit style of type casting.

class IntCharConversion
{
public static void main(String[] args)
{
int a='a';
int b=97;
char c='a';
char d=97;
System.out.println("Output of a from instruction int a='a'; is "+a);
System.out.println("Output of b from instruction int b=97; is "+b);
System.out.println("Output of c from instruction char c='a'; is "+c);
System.out.println("Output of d from instruction char d=97; is "+d);
System.out.println("Output of (int) c from instruction char c='a'; is "+(int) c);
System.out.println("Output of (char) b from instruction int b=97; is "+(char) b);
}
}

Character Boxing (Converting to object of Character Class) #3526

Converting a character to it equivalent Wrapper class object so that many methods can be applied on it.

class CharBoxing
{
public static void main(String[] args)
{
Character ch1='x';
System.out.println(Character.isDigit(ch1));
Character ch2=new Character('1');
System.out.println(Character.isDigit(ch2));
}
}

Character isMethods isDigit isLetter isLetterOrDigit isLowerCase isUpperCase isWhitespace #3531

Using isMethods on character like isDigit(), isLetter(), isLetterOrDigit, isUpperCase(), isLowerCase(), isWhitespace() and getting the boolean or true/false status returned

class CharIsMethods
{
public static void main(String[] args)
{
int dg=0,lt=0,ltdg=0,lc=0,uc=0,ws=0;
char a[]={'1','a','b','2','c','C',' ','t'};
for(int i=0;i<8;i++)
{
if(Character.isDigit(a[i])) dg++;
if(Character.isLetter(a[i])) lt++;
if(Character.isLetterOrDigit(a[i])) ltdg++;
if(Character.isLowerCase(a[i])) lc++;
if(Character.isUpperCase(a[i])) uc++;
if(Character.isWhitespace(a[i])) ws++;
}
System.out.println("Counts in array with 1,a,b,2,c,C, ,t is:");
System.out.println("Digits = "+dg);
System.out.println("Letters = "+lt);
System.out.println("Letters or Digits = "+ltdg);
System.out.println("Lowercase = "+lc);
System.out.println("Uppercase = "+uc);
System.out.println("Whitespace = "+ws);
}
}
Solved Problems

Count isLetter set in the ASCII code set #3549

Write a java program to count the number of letters in the ascii character ra

Exam Questions

Code Sheets:4  Solved Problems:1  Exam Questons:2 
Back