Conversion between data types (including Parsing), and String formatting Flashcards
1
Q
What correctly shows how to create a variable called number with the value of 5?
A
long number = Math.round(4.67);
2
Q
Given the code below, what would the output be?
int number = 12;
String numberString = Integer.toString(number,8);
System.out.println(numberString);
A
14
3
Q
When using the DecimalFormat class in Java, which of the following symbols is used to represent a digit that will be displayed?
A
0
4
Q
Given the code below, which one statement is true?
String text = "FACADE"; int number = Integer.valueOf(text,16); if (number > 6) { System.out.println("X"); } else if (number < 0) { System.out.println("Y"); } else { System.out.println("Z"); }
A
X is printed
5
Q
When using the DecimalFormatter class in Java, which of the following would be used to avoid including leading or trailing zeros when a number is formatted to a String?
A
#
6
Q
Given the code below, what is output?
String text = "-1011"; int number = Integer.parseInt(text); switch (number) { case -1011: System.out.println("A"); break; case -7: System.out.println("B"); break; case 7: System.out.println("C"); break; case 1011: System.out.println("D"); break; }
A
A