100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
CSC 1350 Exam #2 questions with 100% correct answers $20.49   Add to cart

Exam (elaborations)

CSC 1350 Exam #2 questions with 100% correct answers

 0 view  0 purchase
  • Course
  • CSC 1350
  • Institution
  • CSC 1350

CSC 1350 Exam #2 questions with 100% correct answers

Preview 4 out of 41  pages

  • November 16, 2024
  • 41
  • 2024/2025
  • Exam (elaborations)
  • Questions & answers
  • CSC 1350
  • CSC 1350
avatar-seller
BravelRadon
CSC 1350 Exam #2 questions with 100%
correct answers

What are the two parts of an if statement?

a) An increment and a return value

b) An increment and a body

c) A check and an increment

d) A condition and a body - correct answer ✔✔d) A condition and a body



Which of the following statements is true about the if statement?



a) The if and else blocks should always be included within curly braces

b) The else block is optional

c) The if statement can have only one condition that evaluates to an integer value

d) The if block is optional - correct answer ✔✔b) The else blocks is optional



The following code snippet contains an error. What is the error?

if (cost > 100); {

cost = cost -10;

}

System.out.println("Discount cost: " + cost);

a) Logical error: use of an uninitialized variable

b) Logical error: if statement has do-nothing statement after if condition

c) Syntax error (won't compile)

d) Logical error: assignment statement does not show equality - correct answer ✔✔b) Logical error: if
statement has do-nothing statement after if condition



What is the output of the following code snippet?

,int num = 100;

if (num > 100); {

num = num - 10;

}

System.out.println(num);

a) 100

b) 101

c) 90

d) 99 - correct answer ✔✔c) 90



The operator !> stands for ____________________.

a) Not greater than

b) This is not an operator in Java.

c) Not less than

d) Not equal to - correct answer ✔✔b) This is not an operator in Java.



What is the output of the following code snippet?

int x = 50;

if (x > 100) {

x++;

}

else {

x--;

}

System.out.println(x);

a) 50

b) 51

c) 49

d) 52 - correct answer ✔✔c) 49

,Assuming that the user enters 60 as the input, what is the output after running the following code
snippet?

int num = 0;

Scanner in = new Scanner(System.in);

System.out.print("Enter a number: ");

num = in.nextInt();

if (num < 10) {

System.out.println("Too small!");

}

else if (num < 50) {

System.out.println("Intermediate!");

}

else if (num < 100) {

System.out.println("High!");

}

else {

System.out.println("Too high!");

}

a) Too high!

b) Intermediate!

c) High!

d) Too small! - correct answer ✔✔c) High!



What is the output after running the following code snippet?

int number = 600;

if (number < 200) {

System.out.println("Low spender");

}

, else if ( number < 500) {

System.out.println("Spending in moderation");

}

else if (number < 1000) {

System.out.println("Above average!");

}

else {

System.out.println("High Roller!");

} - correct answer ✔✔b) Above average!



An if statement inside another if statement is called a ______________________.

a) break statement

b) syntax error, since that is not permitted in Java

c) switch statement

d) nested if statement - correct answer ✔✔d) nested if statement



Assuming that a user enters 10, 20, and 30 as input values one after another, separated by spaces, what
is the output of the following code snippet?

int num1 = 0;

int num2 = 0;

int num3 = 0;

Scanner in = new Scanner(System.in);

System.out.print("Enter a number: ");

num1 = in.nextInt();

System.out.print("Enter a number: ");

num2 = in.nextInt();

System.out.print("Enter a number: ");

num3 = in.nextInt();

if (num1 > num2) {

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 BravelRadon. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $20.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
$20.49
  • (0)
  Add to cart