|
No. |
Java Question |
Answer/Output |
Explanation |
|
1 |
SOP((a<5) ? 9.9 : 9); |
9.0 |
The result of ternary operator is determined at compile time and here type chosen
using the rules of promotion for binary operands is double. |
|
2 |
SOP( (16>>2) = = ((16/2) ^2)); |
False |
|
|
3 |
double d = 10.0/-0;
if(d = = Double.POSITIVE_INFINITY) SOP("Success"); |
True |
Because there is no such thing as positive or negative zero. So, the result is always
positive infinity |
|
4 |
int x = -8;
int y = ~-33;
x>>>y;
SOP(x); |
-8 |
- |
|
5 |
byte b = (byte)(long)59.3; |
No Errors |
- |
|
6 |
byte b = (int)18.9; |
No Errors |
- |
|
7 |
SOP(0 x -0); |
0 |
- |
|
8 |
SOP(0.0 x -0.0); |
-0.0 |
- |
|
9 |
SOP(0.0 / 0.0); |
NaN |
- |
|
10 |
SOP(-6.0F % 0.0F); |
NaN |
- |
|
11 |
SOP(7.0 / 0.0); |
Infinity |
- |
|
12 |
SOP(-7.0 / 0.0); |
-Infinity |
- |
|
13 |
SOP(-7.0 / -0.0); |
Infinity |
- |
|
14 |
SOP(7.0 / -0.0); |
-Infinity |
- |
|
15 |
SOP(-0.0 = = 0.0); |
True |
- |
|
16 |
SOP(-0 = = 0); |
True |
- |
|
17 |
double a = 10/0.0;
double b = -11/0.0;
SOP(d = =e); |
False |
Because postive infinity and negative infinity are not equal if both are positive
or both are negative then they are equal. |
|
18 |
double a = 10 *0.0;
double b=-10 * 0.0;
SOP(a= =b); |
True |
- |
|
19 |
SOP(0.0 = = -0.0); |
True |
- |
|
20 |
SOP(i + '0'); |
48 |
- |
|
21 |
int i = 2 + '2';
SOP(i); |
No Compile Time Error |
- |
|
22 |
float a = -10.0f/0.0f;
float b = 10.0f/0.0f;
SOP(a = =b); |
False |
- |
|
23 |
float a = 10.0f/-0.0f;
float b = 10.0f/0.0f;
SOP(a = =b); |
False |
- |
|
24 |
double a = -10.0/0.0;
double b = 10.0/0.0;
SOP(a = =b); |
False |
- |
|
25 |
SOP(-10.0f/0.0f); |
-Infinity |
- |
|
26 |
SOP(10.0f/-0.0f); |
-Infinity |
- |
|
27 |
SOP(-10.0f/-0.0f); |
Infinity |
- |
|
28 |
SOP(10.0f/0.0f); |
Infinity |
- |
|
29 |
SOP(-10.0/0.0); |
-Infinity |
- |
|
30 |
SOP(10.0/-0.0); |
-Infinity |
- |
|
31 |
SOP(-10.0/-0.0); |
Infinity |
- |
|
32 |
SOP(10.0/0.0); |
Infinity |
- |
|
33 |
char ch = 65;
char x;
x = (char) (2 * ch);
SOP(x); |
? |
? is the output displayed. |
|
34 |
double a = -10.7;
int i = (int) j;
SOP(i); |
-10 |
- |
|
35 |
double a = 10.6;
int x = (int) y;
SOP(x); |
10 |
- |
|
36 |
byte a = -64;
byte b = -6;
SOP(a/b+","+a%b); |
10,-4); |
- |
|
37 |
double a = 64.5;
double b = 6.0;
SOP(a/b+" "+x%y); |
10.75 4.5 |
- |
|
38 |
SOP(3.0%0); |
NaN |
- |
|
39 |
SOP(3.0/0); |
Infinity |
- |
|
40 |
double a = 1.0;
double b = 0.0;
a = a/b;
byte x = (byte)a;
SOP(x);
|
-1 |
- |
|
41 |
double a = 1.0;
double b = 0.0;
a = a/b;
byte x = (byte)a;
int i = x;
SOP(i);
|
-1 |
- |
|
42 |
byte a =4;
byte b = --a;
SOP(b); |
Compile Time Error |
Because of cast problem |
|
43 |
byte a =4;
byte b = (byte)- -a;
SOP(b); |
4 |
- |
|
44 |
int i=0,j=1;
int c = j>0? i+j : j+j;
int d = j<0?i+j:j+j;
SOP(c);SOP(d); |
1
2 |
- |