What will be the output of the following Java program? [code] class Output { public static void main(String args[])

What will be the output of the following Java program?
Code:
    class Output 
    {
        public static void main(String args[])
        {
	    String str = "true false";
            boolean x = Boolean.parseBoolean(str);
            System.out.print(x);
        }
    }
A. True
B. False
C. System Dependent
D. Compilation Error
 
Answer: b
Explanation: parseBoolean() Parses the string argument as a boolean. The boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string “true”.
Example: Boolean.parseBoolean(“True”) returns true.
Example: Boolean.parseBoolean(“yes”) returns false.
Output:
Code:
$ javac Output.java
$ java Output
false
 

Tìm kiếm

Back
Top