Using Wrappers
Because wrappers and primitives often look very similar in code, it takes some practice to work with wrappers. Wrapper classes come with a number of important methods that make comparing, converting, and generally working with data easier. In this exercise, you will experiment with several wrapper methods and fields.
Este ejercicio forma parte del curso
Data Types and Exceptions in Java
Instrucciones del ejercicio
- Compare the value of
pitoeulersvalue using the.compareTo()method. - Print out the maximum allowed
shortprimitive value. - Parse the string
"true"to abooleanprimitive usingBoolean's.parseBoolean()method.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
public class ExamineWrappers {
public static void main(String[] args) {
Double pi = 3.14;
Double eulers = 2.71828;
// Compare pi's value to euler's
int x = ____.____(____);
System.out.println(x);
// Use Short to print out the maximum short
System.out.println(____.____);
// Use Boolean to turn string "true" to a boolean
boolean y = ____.____("____");
System.out.println(y);
}
}