Originally posted by Parameswaran Thangavel:
i didn't get how equals print true
1)
class SS
{
static public void main(String args[])
{
Double a = new Double(Double.NaN);
Double b = new Double(Double.NaN);
if( Double.NaN == Double.NaN )
System.out.println("True");
else
System.out.println("False");
if( a.equals(b) )
System.out.println("True");
else
System.out.println("False");
}
}
Note that in most cases, for two instances of class Double, d1 and d2, the value of d1.equals(d2) is true if and only if
d1.doubleValue() == d2.doubleValue()
also has the value true. However, there are two exceptions:
If d1 and d2 both represent Double.NaN, then the equals method returns true, even though Double.NaN==Double.NaN has the value false. If d1 represents +0.0 while d2 represents -0.0, or vice versa, the equal test has the value false, even though +0.0==-0.0 has the value true.
SCJA 1.0 (98%), SCJP 1.4 (98%)
Originally posted by Parameswaran Thangavel:
2)why the following code didn't get errors
class R
{
void m()
{
}
}
class SS extends R
{
static public void main(String args[])
{
Float b=new Float("12.12");
}
}
the float value is by default Double; even if i give 12.12d the compiler is not complaining. why??
SCJA 1.0 (98%), SCJP 1.4 (98%)
Originally posted by Parameswaran Thangavel:
3)whts the o/p
class Test
{
Test(int i)
{
System.out.println("Test(" +i +")");
}
}
public class Q12
{
static Test t1 = new Test(1);
Test t2 = new Test(2);
static Test t3 = new Test(3);
public static void main(String[] args)
{
Q12 Q = new Q12();
}
}
SCJA 1.0 (98%), SCJP 1.4 (98%)
Originally posted by Parameswaran Thangavel:
4)
class SS
{
static public void main(String args[])
{
byte d=(byte)12;
d=~d;//Throwiing error why???
System.out.println(d);
}
}
5)
solve
when i am using the byte in the place of char i able to get the full range b4 overflow occurs.but in case of char the chr ? is printed which shows that b is not incrementing why it so?
class SS
{
static public void main(String args[])
{
char b = 1;
while ( ++b > 0 )
System.out.println(b); ;
System.out.println("Welcome to Java");
}
}
6) ans is b how
: public void check()
2: {
3: System.out.println(Math.min(-0.0,+0.0));
4: System.out.println(Math.max(-0.0,+0.0));
5: System.out.println(Math.min(-0.0,+0.0) == Math.max(0.0,+0.0));
6: }
A) prints -0.0, +0.0 and false.
B) prints -0.0, +0.0 and true.
C) prints 0.0, 0.0 and false.
D) prints 0.0, 0.0 and true.
Unlike the the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero.
-- API for the Math class
SCJA 1.0 (98%), SCJP 1.4 (98%)
Originally posted by Parameswaran Thangavel:
hi joe thanx for ur reply still i had some doubt let me put it
1) i read that wrapper objeect are overridden like String obects is that true..
2)i didn't get this point. though the valueOf() method are used to convert the string..
the floating point literal which is 12.12 is by default should be Double or even i gave the double d explicitly.my point here is while converting the string NumberFormat Exception should thrown but didn't why....
5) i put this in other way why ? is printing always...There should be a value for 256 characters.
SCJA 1.0 (98%), SCJP 1.4 (98%)
Just the other day, I was thinking ... about this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|