Question 1 of 10
An orchard kiosk stores a crate mass in a wrapper. What text does this Java code display?
Double kilos = 8.5;
System.out.print(kilos);
- A. 8.5
- B. 8
- C. a compile-time error
- D. null
An orchard kiosk stores a crate mass in a wrapper. What text does this Java code display?
Double kilos = 8.5;
System.out.print(kilos);
A canyon gauge unboxes a depth before doubling. What text does this Java code display?
Double depth = 2.0;
double meters = depth;
System.out.print(meters * 2);
A radio tower parses a channel code, then boxes it. What text does this Java code display?
int code = Integer.parseInt("7");
Integer wrapped = code;
System.out.print(wrapped);
A rain barrel parser boxes a parsed primitive. What text does this Java code display?
Double rain = Double.parseDouble("0.75");
System.out.print(rain);
A lab method expects a Double and halves it. What text does this Java code display?
public class Lab {
public double half(Double n) {
return n / 2;
}
}
Lab lab = new Lab();
System.out.print(lab.half(10.0));
A skip counter is unboxed from a null wrapper. What happens when this Java code runs?
Integer skip = null;
int n = skip;
System.out.print(n);
Two orchard counts start equal, then one wrapper is replaced. What text does this Java code display?
Integer a = 4;
Integer b = 4;
a = a + 1;
System.out.print(a + "," + b);
A dock method returns a boxed primitive. What text does this Java code display?
public class Dock {
public Integer wrap(int n) {
return n;
}
}
Dock d = new Dock();
int raw = 15;
Integer box = d.wrap(raw);
System.out.print(box);
A tag list autoboxes a copy of a primitive. What text does this Java code display?
import java.util.ArrayList;
ArrayList<Integer> tags = new ArrayList<Integer>();
int seed = 6;
tags.add(seed);
seed = 1;
System.out.print(tags.get(0));
A catalog clerk compares packages. Using the table, which statement is true?
| Type | Package | Import required? |
|---|---|---|
| Integer | java.lang | no |
| Double | java.lang | no |
| ArrayList | java.util | yes |