Wrapper Class Java print the range of the integral types (byte,chort,int and lon
ID: 3678691 • Letter: W
Question
Wrapper Class Java
print the range of the integral types (byte,chort,int and long) in columns
create 4 character variables that arfe initialized 'a', 'A', '#', and '6'.
print for each characters whether it's a number, a letter, and/or uppercase
Use a private method to print the letter evaluation
Output
Byte -128 127
short -32,768 32,767
Int -2,147,483,648 2,147,483,647
Long -9,223,372,036,854,775,808 9,223,372,036,854,775,887
a: letter
A: letter uppercase
#:
6: number
we made this code in class
package wrapperClass;
public class LabWrapperClass {
public static void main(String[] args) {
System.out.printf("%9s: %-,30d %,d %n","Byte",Byte.MIN_VALUE,Byte.MAX_VALUE);
System.out.printf("%9s: %-,30d %,d %n","Short",Short.MIN_VALUE,Short.MAX_VALUE);
System.out.printf("%9s: %-,30d %,d %n","Integer",Integer.MIN_VALUE,Integer.MAX_VALUE);
System.out.printf("%9s: %-,30d %,d %n","Long",Long.MAX_VALUE,Long.MAX_VALUE);
// char a = 'a';
// char upperA = 'A';
// char hash = '#';
// char six = '6';
//
// System.out.println("a: " + caseAndNumber(a));
// System.out.println("A: " + caseAndNumber(upperA));
// System.out.println("#: " + caseAndNumber(hash));
// System.out.println("6: " + caseAndNumber(six));
// }
//
// private static String caseAndNumber(char a){
// String letter;
// if(Character.isAlphabetic(a)){
// letter = Character.isUpperCase(a) ? "letter uppercase" : "letter";
// }else
// letter = Character.isDigit(a) ? "number" :"";
// return letter;
}
}
Explanation / Answer
public class LabWrapperClass {
public static void main(String[] args) {
System.out.printf("%9s: %-,30d %,d %n","Byte",Byte.MIN_VALUE,Byte.MAX_VALUE);
System.out.printf("%9s: %-,30d %,d %n","Short",Short.MIN_VALUE,Short.MAX_VALUE);
System.out.printf("%9s: %-,30d %,d %n","Integer",Integer.MIN_VALUE,Integer.MAX_VALUE);
System.out.printf("%9s: %-,30d %,d %n","Long",Long.MAX_VALUE,Long.MAX_VALUE);
char a = 'a';
char upperA = 'A';
char hash = '#';
char six = '6';
System.out.println("a: " + caseAndNumber(a));
System.out.println("A: " + caseAndNumber(upperA));
System.out.println("#: " + caseAndNumber(hash));
System.out.println("6: " + caseAndNumber(six));
}
private static String caseAndNumber(char a){
String letter;
if(Character.isAlphabetic(a)){
letter = Character.isUpperCase(a) ? "letter uppercase" : "letter";
}else
letter = Character.isDigit(a) ? "number" :"";
return letter;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.