Java
Programming and Technical
Programming
Program
What is the output of this program?
class conversion {
public static void main(String args[])
{
double a = 295.04;
int b = 300;
byte c = (byte) a;
byte d = (byte) b;
System.out.println(c + " " + d);
}
}
a) 38 43
b) 39 44
c) 295 300
d) 295.04 300
Read Solution (Total 12)
-
- Type casting a larger variable into a smaller variable results in modulo of larger variable by range of smaller variable. b contains 300 which is larger than byte’s range i:e -128 to 127 hence d contains 300 modulo 256 i:e 44.
- 10 years agoHelpfull: Yes(16) No(1)
- b)
if we downcast the value into the byte at if in double 128 is equals to -128 in byte so.. 256 it becomes 0(295-256=39)and loss of precision 0.4,
second case same 300-256=44
so b) 39 44 is the answer - 10 years agoHelpfull: Yes(5) No(1)
- in java the byte range is frm -127 to 128 so if the value will exceed 257 then it will start counting from ! lyk if we convert int a=257 to bye it will take as 1 and so on so 300 will be taken as 44 and int float there will be lost of precision .4
so answer is B - 10 years agoHelpfull: Yes(2) No(0)
- on type casting..the answer will be option b.
- 10 years agoHelpfull: Yes(1) No(1)
- we know that byte range is -128 to 127
so the total is 256(128+127)
then
295.04-256=39
similarly
300-256=44 - 9 years agoHelpfull: Yes(1) No(0)
- ans is B i.e. 39 44
- 10 years agoHelpfull: Yes(0) No(0)
- b)39
44
- 9 years agoHelpfull: Yes(0) No(0)
- 294.04 -256=38.06 wich is near to 39
- 9 years agoHelpfull: Yes(0) No(0)
- b)
Because Down Casting - 8 years agoHelpfull: Yes(0) No(0)
- i suppose option b is correct because when you down cast the data you are actually taking its mod with range here mod with range of byte ie 256
- 8 years agoHelpfull: Yes(0) No(0)
- b is the answer
- 7 years agoHelpfull: Yes(0) No(0)
- option b
here used Bitwise operator. so 300 change in 44 and 295.04 changed in 39 - 7 years agoHelpfull: Yes(0) No(0)
Java Other Question