double a = 5.5; int x = (int)a ; System.out.println(x) ; What will be the output?
Answers
Answered by
4
Answer:
The output would be 5. Because when you convert decimal number to int, it always round down so 5.5 becomes 5.
Explanation:
MARK ME BRAINLIEST IF IT HELPS YOU!
Answered by
0
x is 5.5
JAVA CODE
double a = 5.5;
int x = (int)a ;
System.out.println(x) ;
OUTPUT
5.5
- Changing a variable from one data type to another is known as type casting. If it makes sense, the compiler will automatically convert one type of data into another. For instance, the compiler will change an integer value to a floating-point value if you assign it to a floating-point variable.
- When you assign a value of one data type to another in Java, it's possible that the two types are incompatible. Java will do the conversion automatically, or "automatically," if the data types are compatible. Although it's done fairly, occasionally mistakes do happen. In Java, typecasting is also referred to as type conversion.
- When a method returns data of a type in a different form and we need to execute an operation, typecasting is frequently required.
#SPJ2
Similar questions