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);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly