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)

CS160 Exam 2 Questions With Correct Answers.

Rating
-
Sold
-
Pages
10
Grade
A+
Uploaded on
17-05-2026
Written in
2025/2026

CS160 Exam 2 Questions With Correct Answers.

Institution
CS160
Course
CS160

Content preview

CS160 Exam 2 Questions With Correct
Answers

How many iterations (if any)will the following loop make?
| | | | | | | | |




for(int a = 0; a < 4; a++) {} - CORRECT ANSWER✔✔-4
| | | | | | | | | | |




How many iterations (if any)will the following loop make?
| | | | | | | |




for(int b = 5; b >= 0; b--) {} - CORRECT ANSWER✔✔-6
| | | | | | | | | | |




How many iterations (if any)will the following loop make?
| | | | | | | |




for(int c = 25; c > 45; c+= 5) {} - CORRECT ANSWER✔✔-0
| | | | | | | | | | | |




How many iterations (if any)will the following loop make?
| | | | | | | |




for (int d = 0; d <= 17; d += 3) {} - CORRECT ANSWER✔✔-6
| | | | | | | | | | | | | |




while (true) {} - CORRECT ANSWER✔✔-infinite
| | | | |




When is it better or preferable to use a while loop instead of a for loop? -
| | | | | | | | | | | | | | | | |


CORRECT ANSWER✔✔-It is better to use a while loop when the number of
| | | | | | | | | | | | |


iterations is not known in advance, such as when dealing with random numbers
| | | | | | | | | | | | |


or type safe user input.
| | | |

, When is it better or preferable to use a for loop instead of a while loop? -
| | | | | | | | | | | | | | | | |


CORRECT ANSWER✔✔-It is better to use a for loop when the number of
| | | | | | | | | | | | |


iterations is known in advance, such as when processing Strings, lists, or dealing
| | | | | | | | | | | | |


with input of a fixed size.
| | | | |




Write some selection statements for a number guessing game that can help
| | | | | | | | | | | |


determine how a user inputted guess is related to the hidden number. As a part
| | | | | | | | | | | | | | |


of your solution you can use two int variables with identifiers guess and
| | | | | | | | | | | | |


secretNumber, which you can assume have been previously declared and | | | | | | | | | |


initialized. Your code should print out the message "Too high", "Too low", or
| | | | | | | | | | | |


|"Correct" based on how the guess is related to the secret number. You do not
| | | | | | | | | | | | | | |


need to worry about reading input or handling multiple guesses. - CORRECT
| | | | | | | | | | | |


ANSWER✔✔-if(guess > secretNumber) { | | |




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




}
else if (guess < secretNumber) {
| | | | |




| System.out.println("Too low"); | |




}
else { |




| System.out.rpintln("Correct"); |




}


Write a boolean expression involving a variable with the identifier speed that
| | | | | | | | | | | |


evaluates to true when speed is greater than 75 or less than or equal to 44 and
| | | | | | | | | | | | | | | | |


assign that result to a boolean variable that you declare. - CORRECT ANSWER✔✔-
| | | | | | | | | | | |


boolean getsTicket = speed > 75 || speed <= 44;
| | | | | | | | |

Written for

Institution
CS160
Course
CS160

Document information

Uploaded on
May 17, 2026
Number of pages
10
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$14.49
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.
Lectphilip West Virginia University
Follow You need to be logged in order to follow users or courses
Sold
263
Member since
2 year
Number of followers
6
Documents
24135
Last sold
3 days ago
WELCOME TO LECTPHILIP, A PLACE WHERE WE UNLOCK YOUR ACADEMIC OPPORTUNITIES

On this page, you find all documents, package deals and flashcards offered by seller lectphilip

4.0

41 reviews

5
20
4
8
3
9
2
2
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