Posts
Find and correct the error in the following code. double x = 10.5; int y = x;
Find and correct the error in the following code.
double x = 10.5;
int y = x;
♨Given data:
double x = 10.5;
int y = x;
♨Required:
Find?
And
Correct?
♨Solution:
Case 1 Find:
As
double x = 10.5;
So x is find
x=10.5;
Now
int y = x;
So y=x;
Means put x value in y
as y=10.5;
Case 2 Correct:
Now correct y value
So y is int type
So it become y=10;
(And
.5 ignore....Due to float type)
double x = 10.5;
int y = x;
The double variable can hold very large (or small) numbers. The maximum and minimum values are 17 followed by 307 zeros.
( While int only holds integers type data not float
Eg:-
x=13;
But not x=13.7;)
The double variable is also used to hold floating point values. A floating point value is one like 8.7, 12.5, 10.1. In other words, it has a "point something" at the end. If you try to store a floating point value in an int variable, NetBeans will underline the faulty code. If you try to run the programme, the compiler will throw up an error message.