Home » JAVA Programming » Characters » Question
  1. What is the output of this program?

    public class output
    {
    public static void main(String args[])
    {
    char ch[]={'p', '1', 'b' ,' ' ,'P' , '0'};
    for (int k = 0; k < 5; ++k)
    {
    if(Character.isDigit(ch[k]))
    System.out.println(ch[k]+" is a digit");
    if(Character.isWhitespace(ch[k]))
    System.out.println(ch[k]+" is a Whitespace character");
    if(Character.isUpperCase(ch[k]))
    System.out.println(ch[k]+" is an Upper case Letter");
    if(Character.isLowerCase(ch[k]))
    System.out.println(ch[k]+" is a lower case Letter");
    k=k+3;
    }
    }
    }
    1. b is a lower case Letter
      is White space character
    2. p is a lower case Letter
      is White space character
    3. p is a lower case Letter
      0 is a digit
    4. p is a lower case Letter
      P is an upper case Letter
    5. None of these
Correct Option: D

Character.isDigit(ch[k]),Character.isUpperCase(ch[k]),Character.isWhitespace(ch[k]) are the function of library java.lang. They are used to find weather the given character is of specified type or not. They return true or false i:e Boolean variable.



Your comments will be displayed only after manual approval.