Vous êtes sur la page 1sur 10

Test: JFo Section 3 Quiz 1 - L1-L2

Review your answers, feedback, and question scores below. An asterisk


(*) indicates a correct answer.

Section 3 Quiz 1 - L1-L2


(Answer all questions in this section)
1. Identify the names of two variables used in the given code.

public class Variables {


public static void main(String args[]) {
String strVal = "Hello";
int intVal = 0;
System.out.println("Integer: " +intVal)
}
}
Mark for Review

(1) Points
int
String
intVal(*)
strVal(*)
Hello
Correct

2. Java is a strongly typed language; therefore you must declare a data


type for all variables.
Mark for Review

(1) Points
True (*)
False
Correct

3. Identify the variable declared in the given code.

public class Welcome {


public static void main(String args[]) {
int a = 2;
System.out.println("a is " + a);
}
}
Mark for Review

(1) Points
a (*)
Welcome
int
2
Correct

4. Which is valid syntax to declare and initialize a String variable?


Mark for Review

(1) Points
String x = Java;
String x= “Java”; (*)
String “x” = Java;
String “x” = “Java”;
Correct

5. What is the output?

public class Hello {


public static void main(String args[]) {
String str = ”Hello”;
str = ”World”;
System.out.println(str);
}
}
Mark for Review

(1) Points
Hello
World
Hello World
Hello
World (*)
Correct
Page 1 of 3 Next

Test: JFo Section 3 Quiz 1 - L1-L2


Review your answers, feedback, and question scores below. An asterisk
(*) indicates a correct answer.
Section 3 Quiz 1 - L1-L2
(Answer all questions in this section)
6. Which two data types are appropriate for their variable?
Mark for Review

(1) Points
String firstName = “Alex”;(*)
int averageDollarAmount = 19.95;
double checkingAmount = 1500;(*)
boolean age = 20;
Correct

7. Which two statements will not compile?


Mark for Review

(1) Points
int break=10;(*)
int age=20;
double double=10;(*)
double salary = 20000.34;
int abc = 10;
Correct

8. This declaration represents a long data type.


long a = 123L;
Mark for Review

(1) Points
True (*)
False
Correct

9. What is the range of the byte data type?


Mark for Review

(1) Points
–27 to 27–1 (*)
–215 to 215–1
–231 to 231–1
–263 to 263–1
Correct
10. Which of the following data types is the largest?
Mark for Review

(1) Points
byte
short
int
long (*)
Correct
Previous Page 2 of 3 Next

Test: JFo Section 3 Quiz 1 - L1-L2


Review your answers, feedback, and question scores below. An asterisk
(*) indicates a correct answer.

Section 3 Quiz 1 - L1-L2


(Answer all questions in this section)
11. What is the output? public static void main(String args[]) {
int x = 100;
int y = x;
y++;
System.out.println("Value of x is " + x);
System.out.println("Value of y is " + y);
}
Mark for Review

(1) Points
Value of x is 0
Value of y is 1
Value of x is 100
Value of y is 1
Value of x is 100
Value of y is 1
Value of x is 100
Value of y is 101 (*)
Correct

12. How many bits are in a byte?


Mark for Review

(1) Points
2
4
6
7
8 (*)
Correct

13. Which two are mathematical operators?


Mark for Review

(1) Points
+(*)
–(*)
#
@
Correct

14. Which keyword makes a variable’s value unchangeable?


Mark for Review

(1) Points
const
final (*)
static
break
Correct

15. Which data type is most commonly used to represent numeric data?
Mark for Review

(1) Points
int (*)
float
String
short
Correct
Previous Page 3 of 3
Test: JFo Section 3 Quiz 2 - L3-L5
Review your answers, feedback, and question scores below. An asterisk
(*) indicates a correct answer.

Section 3 Quiz 2 - L3-L5


(Answer all questions in this section)
1. Which two statements are correct about the usage of an underscore?
Mark for Review

(1) Points
Underscores do not affect the value of the variable.(*)
Underscores change the value of the number.
Underscores help make large numbers more readable.(*)
Underscores help the compiler interpret large numbers.
Correct

2. A double with the value of 20.5 is cast to an int. What is the value of
the int?
Mark for Review

(1) Points
20.5
21
20 (*)
25
Correct

3. When the result of an expression is assigned to a temporary memory


location, what is the size of memory allocated?
Mark for Review

(1) Points
A default size is allocated.
The size of the largest data type used in the expression. (*)
The size of the smallest data type used in the expression.
The size of the any data type used in the expression.
Correct

4. What is the correct way to cast a long to an int?


Mark for Review

(1) Points
int longToInt = 20L;
int longToInt = int 20L;
int longToInt = (int)20L; (*)
int longToInt = 20L(int);
Correct

5. Which two statements are true about type casting?


Mark for Review

(1) Points
Type casting retains the size of the value or the original data type.
Type casting changes the type of the value stored.(*)
Type casting lowers the range of possible values.(*)
Type casting cannot be performed on equations.
Correct
Page 1 of 3 Next

Test: JFo Section 3 Quiz 2 - L3-L5


Review your answers, feedback, and question scores below. An asterisk
(*) indicates a correct answer.

Section 3 Quiz 2 - L3-L5


(Answer all questions in this section)
6. Which is a valid way to parse a String as an int?
Mark for Review

(1) Points
int intVar1 = "100";
int intVar1 = Integer.parseInt("One Hundred");
int intVar1 = Integer.parseInt("100"); (*)
nt intVar1 = (int)"100";
Correct

7. System.in readies Scanner to collect input from the console.


Mark for Review

(1) Points
True (*)
False
Correct
8. These two code fragments perform the same task.

// Fragment 1
String inputString = JOptionPane.showInputDialog("??");
int input = Integer.parseInt(inputString);
input++;

// Fragment 2
int input = Integer.parseInt(JOptionPane.showInputDialog("??")) + 1;
Mark for Review

(1) Points
True (*)
False
Correct

9. You write a statement that assigns a value to a String variable as


shown below.

String input = ”This is Java Program”;

This way of assigning values to variables is known as hard-coding.


Mark for Review

(1) Points
True (*)
False
Correct

10. A character preceded by backslash is called an escape sequence.


Mark for Review

(1) Points
True (*)
False
Correct
Previous Page 2 of 3 Next

Test: JFo Section 3 Quiz 2 - L3-L5


Review your answers, feedback, and question scores below. An asterisk
(*) indicates a correct answer.

Section 3 Quiz 2 - L3-L5


(Answer all questions in this section)
11. char is the primitive textual data type in Java.
Mark for Review

(1) Points
True (*)
False
Correct

12. What is the output?

public static void main(String args[]) {


String greet1 = "Hello";
String greet2 = "World";
String message2 = greet1 +" " +greet2 +" " +2016 +"!";
System.out.println(message2);
}
Mark for Review

(1) Points
Hello World
“Hello World 2016”
Hello World 2016 ! (*)
“Hello” “World” “2016” “!”
Correct

13. An Object cannot have String objects as properties.


Mark for Review

(1) Points
True
False (*)
Correct

14. Given the expression:

String message = ”Hello World”;

Which is the String Literal?


Mark for Review

(1) Points
message
Hello World (*)
String message
String message = ”Hello World”;
Correct

15. Char data types cannot handle multiple characters.


Mark for Review

(1) Points
True (*)
False
Correct
Previous Page 3 of 3

Vous aimerez peut-être aussi