Quiz3 1

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 6

Section 3 Quiz 1 - L1-L2

(Answer all questions in this section)

1. 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

int

Welcome

a (*)

Correct Correct

2. What is the output?

public class Welcome {


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

This is my first program

a=2

This is my first program a is 2 (*)

This is my first program a is + a

Correct Correct
3. Which two are valid assignments of a? Mark for Review
(1) Points

(Choose all correct answers)

int a = 10

int a; a = 10; (*)

int a = 10; (*)

int a = �10�;

Correct Correct

4. Which two are valid? Mark for Review


(1) Points

(Choose all correct answers)

double doubleVar1 = 3.1; double doubleVar2 = 3.1; (*)

double doubleVar1; doubleVar2 = 3.1.

double doubleVar1, double doubleVar2 = 3.1;

double doubleVar1, doubleVar2 = 3.1; (*)

Incorrect Incorrect. Refer to Section 3 Lesson 1.

5. 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 Correct
6. Java is a strongly typed language; therefore you must declare a data type for
all variables. Mark for Review
(1) Points

True (*)

False

Correct Correct

7. 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

(Choose all correct answers)

strVal (*)

Hello

String

int

intVal (*)

Correct Correct

8. Which data type is most commonly used to represent numeric data?


Mark for Review
(1) Points

int (*)
float

String

short

Correct Correct

9. Which two are mathematical operators? Mark for Review


(1) Points

(Choose all correct answers)

+ (*)

� (*)

Correct Correct

10. Assuming x is an int, which of the following are ways to


increment the value of x by 1? Mark for Review
(1) Points

(Choose all correct answers)

x = x +1; (*)

x = +1;

x+;

x++; (*)

x += 1; (*)
Correct Correct
11. Which of the following data types is the largest? Mark for Review
(1) Points

byte

short

int

long (*)

Correct Correct

12. What value is assigned to x?

int x = 25 - 5 * 4 / 2 - 10 + 4; Mark for Review


(1) Points

9 (*)

34

Correct Correct

13. 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 Correct

14. Which two are recommended practices for naming final variables?
Mark for Review
(1) Points

(Choose all correct answers)

Capitalize every letter (*)

Separate words with an underscore (*)

Capitalize first letter

Separate words with an space

Incorrect Incorrect. Refer to Section 3 Lesson 2.

15. 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 Correct

You might also like