0
0
Javaprogramming~10 mins

Type promotion in Java - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a variable that can hold a decimal number.

Java
double number = [1];
Drag options to blanks, or click blank then click option'
A'a'
B5.5
Ctrue
D100
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning a boolean or character to a double variable.
Assigning an integer without decimal to a double variable (though allowed, the question expects a decimal).
2fill in blank
medium

Complete the code to promote an int to a double by assignment.

Java
int i = 10;
double d = [1];
Drag options to blanks, or click blank then click option'
Ai + 0.5
B"10"
Ci
D(double) i + 1.0
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to cast unnecessarily or adding values.
Assigning a string instead of a number.
3fill in blank
hard

Complete the code to promote a byte to an int using the correct cast.

Java
byte b = 5;
int i = [1] b;
Drag options to blanks, or click blank then click option'
A(int)
Bdouble
C(byte)
D(char)
Attempts:
3 left
💡 Hint
Common Mistakes
Casting to double or char instead of int.
Casting to byte which is the original type.
4fill in blank
hard

Fill both blanks to create a conditional that promotes a short to int and compares it.

Java
short s = 10;
if ([1] s [2] 5) {
    System.out.println("Greater");
}
Drag options to blanks, or click blank then click option'
A(int)
B>
C<
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators.
Not casting before comparison.
5fill in blank
hard

Fill all three blanks to create a map with keys promoted to uppercase strings and values filtered by condition.

Java
Map<String, Integer> result = Map.of(
    "a", 1,
    "b", 2,
    "c", 3
).entrySet().stream()
 .filter(e -> e.getValue() [1] 1)
 .collect(Collectors.toMap(
    e -> e.getKey()[2],
    e -> e.getValue() [3] 1
));
Drag options to blanks, or click blank then click option'
A>
B.toUpperCase()
C+
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators in filter.
Not converting keys to uppercase.
Not incrementing values correctly.