Search Header Logo

Java Basics #2

Authored by Jennifer Hoagland

Computers

10th - 12th Grade

Used 65+ times

Java Basics #2
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

7 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

15 mins • 1 pt

Consider the following code segment:

Line 1: int a = 10;

Line 2: double b = 10.7;

Line 3: double c = a + b;

Line 4: int d = a + c;

Line 5: System.out.println(c + " " + d);


What will be output as a result of executing the code segment?

20 20

20.0 30

20.7 31

20.7 30.7

Nothing will be printed because of a compile-time error.

2.

MULTIPLE CHOICE QUESTION

15 mins • 1 pt

Consider the following code segment:

Line 1: int a = 10;

Line 2: double b = 10.7;

Line 3: int d = a + b;


Line 3 will not compile in the code segment above. With which of the following statements could we replace this line so that is compiles?


I. int d = (int) a + b;

II. int d = (int) (a + b);

III. int d = a + (int) b;

I

II

III

I and III

II and III

3.

MULTIPLE CHOICE QUESTION

15 mins • 1 pt

Consider the following code segment:


Line 1: int a = 11;

Line 2: int b = 4;

Line 3: double x = 11;

Line 4: double y = 4;

Line 5: System.out.print(a / b);

Line 6: System.out.print(", ");

Line 7: System.out.print(x / y);

Line 8: System.out.print(", ");

Line 9: System.out.print(a / y);


What is printed as a result of executing the code segment?

3, 2.75, 3

3, 2.75, 2.75

2, 3, 2

2, 2,75, 2.75

Nothing will be printed because of a compile-time error.

4.

MULTIPLE CHOICE QUESTION

15 mins • 1 pt

Consider the following code segment:


int var = 12;

var = var % 7;

var = var - 1;

System.out.println(var);


What is printed as a result of executing the code segment?

0

1

2

4

5

5.

MULTIPLE CHOICE QUESTION

15 mins • 1 pt

Consider the following code segment:


int count = 5;

double multiplier = 2.5;

int answer = (int)(count * multiplier);

answer = (answer * count) % 10;

System.out.println(answer);


What is printed as a result of executing the code segment?

0

2.5

6

12.5

60

6.

MULTIPLE CHOICE QUESTION

15 mins • 1 pt

Assume that a, b, and c have been declared and initialized with int values. The expression


!(a > b || b <= c)


is equivalent to which of the following?

a > b && b <= c

a <= b || b > c

a <= b && b > c

a < b || b >= c

a < b && b >= c

7.

MULTIPLE CHOICE QUESTION

15 mins • 1 pt

Assume that x, y, and z have been declared as follows:


boolean x = true;

boolean y = false;

boolean z = true;


Which of the following expressions evaluates to true?

x && y && z

x && y || z && y

!(x && y) || z

!(x || y) && z

x && y || !z

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?