TutorialsPoint lists a lot of useful methods for all wrapper classes. See below:
https://www.tutorialspoint.com/java/java_characters.htm
https://www.tutorialspoint.com/java/lang/java_lang_integer.htm
https://www.tutorialspoint.com/java/lang/java_lang_double.htm
Challenges:
1. Pick 3 methods from each of the wrapper classes above and demo how they can be used.
import java.util.*;
class Wrap {
public static void main(String[] args) {
Scanner Rapper = new Scanner(System.in);
String input1 = Rapper.nextLine();
String modified1 = "";
for(int i=0; i<input1.length(); i++){
if(Character.isLetter(input1.charAt(i))){
modified1 = modified1 + Character.toUpperCase(input1.charAt(i));
}
if(Character.isWhitespace(input1.charAt(i))){
modified1 = modified1 + input1.charAt(i-1);
}
}
System.out.println(modified1);
int input2 = Rapper.nextInt();
int modified2 = Integer.bitCount(Integer.numberOfTrailingZeros(input2))-Integer.bitCount(Integer.numberOfLeadingZeros(input2));
System.out.println(modified2);
double input3 = Rapper.nextDouble();
if(!Double.isInfinite(input3) && !Double.isNaN(input3)){
String modified3 = Double.toHexString(input3);
System.out.println(modified3);
}
}
}
R7.14
a. int should be Integer
b. missing <Integer> after second ArrayList
c. missing () after ArrayList<>
d. i needs to start at 0
e. i needs to start at 0
R7.17
element matches
NaN NaN
110 110
90 110
100 110
120 110, 120
80 110, 120