100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
COP Exam 2 Questions and Answers $12.49   Add to cart

Exam (elaborations)

COP Exam 2 Questions and Answers

 0 view  0 purchase
  • Course
  • COP
  • Institution
  • COP

COP Exam 2 Questions and Answers

Preview 2 out of 8  pages

  • November 15, 2024
  • 8
  • 2024/2025
  • Exam (elaborations)
  • Questions & answers
  • COP
  • COP
avatar-seller
lectknancy
COP Exam 2 Questions and Answers
After the execution of the following code, what will be the value of num if the input
values are 0? (Assume that console is a Scanner object initialized to the standard input
device.)


int num = console.nextInt();

if (num > 0)
num = num + 13;
else
if (num >= 3)
num = num + 15; - Answer-0

What is the output of the following Java code?


int x = 0;
if (x > 0)
System.out.println("positive ");
System.out.print("zero ");
System.out.println("negative"); - Answer-zero negative

What is the output of the following Java code?


int x = 57;
int y = 3;

switch (x % 9)
{
case 0:
case 1:
y++;
case 2:
y = y - 2;
break;
case 3:
y = y + 2;
case 4:
break;
case 5:
case 6:
y = y + 3;

, }

System.out.println(y); - Answer-5

if (quotaAmt > 100 || sales > 100 && productCode == "C")
bonusAmt = 50;

When the above code is executed, which operator is evaluated first? - Answer-==

Assume x=4 and y=5, which of the following is true? - Answer-x != 4 ^ y == 5

Assume x=4, which of the following is true? - Answer-x != 5

Assume x = 4 and y = 5, which of the following is true? - Answer-x < 5 || y < 5

Which of the following is the correct expression that evaluates to true if the number x is
between 1 and 100 or the number is negative? - Answer-( (x < 100) && (x > 1) ) || (x <
0)

A computer program will recognize both = and == as the equality operator. - Answer-
False

In Java, || has a higher precedence than &&. - Answer-False

Suppose that the input is 6 and console is a Scanner object initialized to the standard
input device. Consider the following code.

int alpha = 7;
int beta = console.nextInt();

switch (beta)
{
case 5:
alpha = alpha + 1;
case 6:
alpha = alpha + 2;
case 7:
alpha = alpha + 3;
default:
alpha = alpha + 5;
}

System.out.print(alpha);

The output of this code is 9. - Answer-False

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller lectknancy. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $12.49. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

75323 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$12.49
  • (0)
  Add to cart