NEW
Font size
WorksheetsCasting in Java
Total questions: 11
Worksheet time: 6mins
Consider the following code segment.
int a = 15;
double b = (double) a / 2.0;
System.out.println(b);
What is printed as a result of executing the code segment?
Consider the following code segment.
int x = 5;
double y = (double) (x * 2);
System.out.print(x + " " + y);
What is printed as a result of executing the code segment?
5 10.0
5 10
10 5.0
10 5
Consider the following code segment.
double num1 = 10.5;
int num2 = (int) num1;
double result = num1 - num2;
System.out.println(result);
What is printed as a result of executing the code segment?
Consider the following code segment.
int m = 8;
double n = (double) (m + 3) / 2;
System.out.print(m + " " + n);
What is printed as a result of executing the code segment?
8 5.5
8 6.0
8 5.0
11 5.5
Consider the following code segment.
double x = 7.0;
int y = (int) x;
double z = x / y;
System.out.println(z);
What is printed as a result of executing the code segment?
Consider the following code segment.
int a = 10;
double b = 3.0;
double c = (double) a / b;
System.out.print(a + " " + b + " " + c);
What is printed as a result of executing the code segment?
Consider the following code segment.
int x = 6;
double y = (double) (x / 2);
System.out.println(x + " " + y);
What is printed as a result of executing the code segment?
6 3.0
6 3
3 3.0
3 3
Consider the following code segment.
double num1 = 9.7;
int num2 = (int) (num1 + 0.5);
System.out.print(num2);
What is printed as a result of executing the code segment?
Consider the following code segment.
double num1 = 3.14;
int num2 = (int) num1;
double result = num1 * num2;
System.out.println(result);
What is printed as a result of executing the code segment?
Consider the following code segment.
double x = 9.5;
int y = (int) (x / 3);
double z = (double) y / 2;
System.out.print(y);
System.out.print(" ");
System.out.print(z);
What is printed as a result of executing the code segment?
3 1.5
3 1.0
2 1.0
2 1.5
Consider the following code segment.
double a = 7;
int b = (int) (a / 2);
double c = (double) b / 2;
System.out.print(b);
System.out.print(" ");
System.out.print(c);
What is printed as a result of executing the code segment?
3 1.5
3.5 1.75
3 1
4 2
