Search Header Logo

APDQ 2.1 - 2.3

Authored by enorberg@dupage88.net enorberg@dupage88.net

Computers

12th Grade

Used 1+ times

APDQ 2.1 - 2.3
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider the following code segment.

int temp = 75;

String choice;

boolean hasSibling = false;

if (temp < 70)

{

choice = "Indoors";

}

else

{

choice = "Outdoors";

}

if (hasSibling)

{

choice += " with sibling";

}

What is the value of choice after executing the code segment?

"Indoors"

"Outdoors"

"Indoors with sibling"

"Outdoors with sibling"

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider the following code segment.

int x = 3;

int y = -1;

if (x - 2 > y)

{

x -= y;

}

if (y + 3 >= x)

{

y += x;

}

System.out.print("x = " + x + ", y = " + y);

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

x = 2, y = 1

x = 3, y = 2

x = 4, y = -1

x = 4, y = 3

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider the following two code segments where the int variable choice has been properly declared and initialized.

Code Segment 1

if (choice > 10)

{

System.out.println("blue");

}

else if (choice < 5)

{

System.out.println("red");

}

else

{

System.out.println("yellow");

}

Code Segment 2

if (choice > 10)

{

System.out.println("blue");

}

if (choice < 5)

{

System.out.println("red");

}

else

{

System.out.println("yellow");

}

Assume that both code segments initialize choice to the same integer value. Which of the following best describes the conditions on the initial value of the variable choice that will cause the two code segments to produce different output?

choice > 5 and choice < 10

choice > 10

choice == 5 or choice == 10

There is no value for choice that will cause the two code segments to produce different output.

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider the following partial Person class definition. The instance variable adult should be set to true if the person’s age is at

least 18 years old, and should be set to false otherwise.

public class Person

{

private String name;

private int age;

private boolean adult;

public Person(String n, int a)

{

name = n;

age = a;

if (age >= 18)

{

adult = true;

}

else

{

adult = false;

}

}

// There are no other constructors.

// There may be other methods that are not shown.

}

Which of the following statements, when appearing in a method in a class other than Person, will correctly a

create an instance of a Person object that represents an adult person?

Person p = new Person("Homer", 23);

Person p = new Person("Homer", "23");

Person p = new Person("Homer", true);

Person p = new Person("Homer", 17);

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

In the following code segment, the int variables a, b, c, and d have been properly declared and initialized.

if (a < b || c != d)

{

System.out.println("dog");

}

else

{

System.out.println("cat");

}

5. Which of the following code segments produces the same output as the given code segment for all values of a, b, c, and d?

if (a < b && c != d)

{

System.out.println("dog");

}

else

{

System.out.println("cat");

}

if (a > b && c == d)

{

System.out.println("cat");

}

else

{

System.out.println("dog");

}

if (a >= b || c == d)

{

System.out.println("cat");

}

else

{

System.out.println("dog");

}

if (a >= b && c == d)

{

System.out.println("cat");

}

else

{

System.out.println("dog");

}

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider the following code segment.

int a = 10;

int b = 5 * 2;

System.out.print(a == b);

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

10

10 == 10

true

false

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider the following code segment. double regularPrice = 100.0; boolean onClearance = true; boolean hasCoupon = false; double finalPrice = regularPrice; if (onClearance) { finalPrice -= finalPrice * 0.25; } if (hasCoupon) { finalPrice -= 5.0; } System.out.println(finalPrice); What is printed as a result of executing the code segment?

20.0

25.0

70.0

75.0

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?