Menu
Topics Index
...
`

Boolean Values 2324


If you need explanation Read this topic

If you need Answer Take test on this topic

Boolean Values 2324
What will be the output of the following program?
public class UsingNaN {
    public static void main(String args[]) {
        Float flo = (float) Math.sqrt(20);
        System.out.println(flo);
        boolean b = Float.isNaN(flo);
        System.out.print(b);
    }
    static public boolean isNaN(float k) {
        return (k == k);
    }
}

A. 4.472136
false
B. 4.472136
true
C. Compilation Error
D. Runtime Error
Topic: Java isInfinite() And isNaN() Methods In Double Class

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

A

Posted by ?????????? ?????    2015-01-05 04:48:36


Ans is A.

square root of 20 will be 4.472136 and we are calling isNaN() method of Float class on variable flo which contains sqrt of 20 so isNaN() method of Float will return false...

So ans will be

4.472136

false

Posted by Gopinath Manchikanti    2015-01-05 04:52:06


ANS IS A

Here the concept of "Wrapper class" is used.
Two functions are used:
1)sqrt()
2)isNaN()

1)sqrt(int no)-->This is static method present in Math classReturns the square root of a number.

----here sqrt(20)-->returns double so typecasting is used to convert double into float-->4.472136 will get printed.

2)isNaN(float no)-->This is static method present in Float wrapper class which is used to determine whether the number passed id "NOT A NO" or not.If it is "NOT A NUMBER" returns "TRUE" else "FALSE"

--Here isNaN(4.472136) is a valid no so it returns false.

Posted by Mânïshå Mùlchåndânï    2015-01-05 08:24:25


This dose is now closed and the winners are Gopinath Manchikanti,  for 'First Correct Comment', Mânïshå Mùlchåndânï,  for 'Best Comment'. The 'lucky liker' is Gopinath Manchikanti. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2015-01-06 05:11:28


© meritcampus 2019

All Rights Reserved.

Open In App