Computer Applications
String s1 = "45.50"; String s2 = "54.50";
double d1=Double.parseDouble(s1);
double d2=Double.parseDouble(s2);
int x= (int)(d1+d2);
What is value of x?
Java Library Classes
ICSE 2024
5 Likes
Answer
100
Reason — The code converts the strings "45.50"
and "54.50"
into doubles using Double.parseDouble()
, resulting in d1 = 45.5
and d2 = 54.5
. Their sum is 100.0
.
Casting 100.0
to an integer using (int)
removes the decimal part, leaving x = 100
.
Answered By
2 Likes
Related Questions
Rewrite the following do while program segment using for:
x = 10; y = 20; do { x++; y++; } while (x<=20); System.out.println(x * y );
Give the output of the following program segment. How many times is the loop executed?
for(x=10; x>20;x++) System.out.println(x); System.out.println(x*2);
Consider the following two-dimensional array and answer the questions given below:
int x[ ][ ] = {{4,3,2}, {7,8,2}, {8, 3,10}, {1, 2, 9}};
(a) What is the order of the array?
(b) What is the value of x[0][0]+x[2][2]?
Differentiate between boxing and unboxing.