Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

Exam 2 CSE 174 ACTUAL UPDATED QUESTIONS AND CORRECT ANSWERS

Rating
-
Sold
-
Pages
37
Grade
A+
Uploaded on
12-06-2026
Written in
2025/2026

Exam 2 CSE 174 ACTUAL UPDATED QUESTIONS AND CORRECT ANSWERS

Institution
CSE
Course
CSE

Content preview

Exam 2 CSE 174 ACTUAL UPDATED QUESTIONS AND CORRECT ANSWERS

Consider the following code snippet: if (number > 30) {


int number = 0;


Scanner in = new Scanner(System.in);
System.out.print("Enter a number: "); number = in.nextInt();
if (number > 30) { . . . }
else if (number > 20) { ....... }
else if (number > 10) { ...... }
else {...... }


Which of the following options is a legally correct if (!a == 10)
expression for inverting a condition?


if (!(a == 10))
if (!a == 10)
if (a ! 10)
if (a !== 10)


What is the output of the following code snippet? his


String someString1 = "his";
String someString2 = "cycle";
if (someString1.compareTo(someString2) < 0) {
System.out.println(someString2);
}
else { System.out.println(someString1);
}

,Which of the following statements is true about the if The else block is optional
statement?


The else block is optional.


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


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


The if block is optional.


if (cost > 100); { Logical error: if statement has do-nothing statement after if condition
cost = cost - 10;
}
System.out.println("Discount cost: " + cost);


Syntax error (won't compile)


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


Logical error: use of an uninitialized variable


Logical error: assignment statement does not show
equality


Consider the following code snippet. What is the Using == to test the double variable average for equality is error-prone.
potential problem with the if statement?


double average; average = (g1 + g2 + g3 + g4) / 4.0;
if (average == 90.0) {
System.out.println("You earned an A in the class!");
}


Literals should never be used in if statement conditionals.


The assignment operator should not be used within an if-
statement conditional.


The conditional will not evaluate to a Boolean value.


Using == to test the double variable average for equality
is error-prone.

,Which of the following is the correct syntax for an if if (x < 10) { size = "Small"; }
statement? else { size = "Medium"; }


if (x < 10) { size = "Small"; }
else { size = "Medium"; }


if (x < 10) { size = "Small"; } else (x < 20) { size = "Medium"; }


if { size = "Small"; }
else (x < 20) { size = "Medium"; }


if (x < 10); { size = "Small"; }
else (x < 20) { size = "Medium"; }


Which of the following variables is used to store a Boolean
condition that can be either true or false?


Algebraic


Logical


Conditional


Boolean


In Java, which of the following orderings is used to Lexicgographic
compare strings?


Semantic


Lexicographic


Alphabetic


Syntactic


Which of the following operators compare using short- &&
circuit evaluation?


++


-


==


&&

, What is the output of the following code snippet if the 24
input is 25?


int i = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
i = in.nextInt();
if (i > 25) {
i++;
} else {
i--;
} System.out.print(i);


26


25


27


24


An if statement inside another if statement is called a nested if statement
_________________.


nested if statement


syntax error, since that is not permitted in Java


break statement


switch statement




Which of the following operators is used to combine two &&
Boolean conditions?


&&


##


$$


%%

Written for

Institution
CSE
Course
CSE

Document information

Uploaded on
June 12, 2026
Number of pages
37
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$19.89
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Briwisescore Stanford University
Follow You need to be logged in order to follow users or courses
Sold
20
Member since
2 year
Number of followers
5
Documents
9901
Last sold
3 weeks ago

1.7

3 reviews

5
0
4
0
3
1
2
0
1
2

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions