Complete the code to convert an integer to a double.
int num = 5; double result = ([1]) num; System.out.println(result);
We use (double) to cast an integer to a double type in Java.
Complete the code to cast a double to an integer.
double pi = 3.14; int whole = ([1]) pi; System.out.println(whole);
(double) instead of (int).To convert a double to an int, use (int) cast. This drops the decimal part.
Fix the error in casting a long to an int.
long bigNumber = 100000L; int smaller = ([1]) bigNumber; System.out.println(smaller);
To cast a long to an int, use (int). Casting to long again is incorrect.
Fill both blanks to create a dictionary with string keys and integer values using casting.
Map<String, Integer> map = new HashMap<>(); String key = "age"; Object value = 30; map.put(key, ([1]) value); int age = ([2]) map.get(key); System.out.println(age);
Cast value to Integer when putting in the map, and cast the retrieved value to int when getting it.
Fill all three blanks to cast and calculate the average of two numbers.
int a = 5; int b = 8; double average = (([1]) a + ([2]) b) / [3]; System.out.println(average);
Cast a and b to double to avoid integer division, then divide by 2.0 to get a double average.
