Can you assign a fractional value to an int by typecasting? What will be the outcome of the following code?
1. /**
2. * @author Nancy
K.A.N.
3. */
4. public class Datatype1 {
5. public static void main(String[] args) {
6. int x= (int)4.7;
7. System.out.println("x="+x);
8. }
9. }
10.
x=4
ReplyDeleteYes. Double value is typecasted to an int value. As typecasting does not round the value. it prints the int part of the number.
DeleteYes, we can but the output will be 4 the integer part only.
ReplyDelete