What will be the output of the following Java program? [code] class output { class output { public static

Lan Anh

New member
What will be the output of the following Java program?
Code:
    class output 
    {
       class output 
       {
         public static void main(String args[])
         {
            char c[]={'A', '1', 'b' ,' ' ,'a' , '0'};
            for (int i = 0; i < 5; ++i)
            {
                   i++; 
                   if(Character.isDigit(c[i]))
                       System.out.println(c[i]+" is a digit");
                   if(Character.isWhitespace(c[i]))
                       System.out.println(c[i]+" is a Whitespace character");
                   if(Character.isUpperCase(c[i]))
                       System.out.println(c[i]+" is an Upper case Letter");
                   if(Character.isLowerCase(c[i]))
                       System.out.println(c[i]+" is a lower case Letter");
                   i++;
            }
        }
    }
A.
a is a lower case Letter
is White space character
B.
b is a lower case Letter
is White space character
C.
1 is a digit
a is a lower case Letter
D.
a is a lower case Letter
0 is a digit
 
Answer: c
Explanation: Character.isDigit(c), Character.isUpperCase(c), Character.isWhitespace(c) are the function of library java.lang they are used to find whether the given character is of specified type or not. They return true or false i:e Boolean variable.
Output:
Code:
$ javac output.java
$ java output  
1 is a digit
a is a lower case Letter

This section of our 1000+ Java MCQs focuses on StringBuffer class’s methods of Java Programming Language.
 

Tìm kiếm

Back
Top