10/11/2024 1:41 PM
CSCI1301 Exam 2 Questions 100% Solved.
True or false: A while loop may execute the body of the loop *zero times* (perform zero
iterations) - answer✔True
A while loop keeps repeating the body of the loop until... - answer✔The controlling Boolean
expression becomes false
What happens if a loop never reaches a stopping point and becomes an infinite loop? -
answer✔You have to abort the program manually
A for-loop has three parts: an initializing action, a Boolean expression, and an update action.
Which one of these three happens for the first time *after* the first iteration of the loop? -
answer✔Update Action
True or false: There are some situations where it is not possible to use a while loop. In these
situations, you must use a for loop. - answer✔False
True or false: It's typically better to use a do-while loop over a while loop if you know the loop
body will execute at least *once*. - answer✔True
, ©SIRJOEL EXAM SOLUTIONS
10/11/2024 1:41 PM
What is the main reason you would use a do-while loop over a while loop? - answer✔If you
want the loop body to execute at least once
What does the *continue* statement do? - answer✔Skips the current iteration of a loop body
True or false: A single array can contain values of *different* data types. - answer✔False
True or false: An array must contain at least *2* elements. - answer✔False
True or false: You could have a program that has 2 arrays. One array stores int values and the
other stores String values. - answer✔True
What index refers to the very first element of an array? - answer✔0
Is an array an object or a primitive type? - answer✔Object
How do you find the number of elements in an array? - answer✔Use arrayName.length
How is an object different from a class? - answer✔A class is a general definition for objects.
Objects are particular instances of the class which have values for the instance variables.
What are the two main things that a class specifies for objects? - answer✔Attributes and actions
(behaviors)
What type of method is the *main* method? - answer✔Void
True or false: Methods may have variables declared inside of them. - answer✔True