CPSC 1110 Questions With Verified
Solutions
Which one of the following statements is correct about the given code snippet?
int[] somearray = new int[6];
for (int i = 1; i < 6; i++)
{
somearray[i] = i + 1;
} CORRECT ANSWERS The for loop initializes all the elements except the first
element.
Suppose you wish to use an array to solve a new problem. What is the first step to take
in finding a solution? CORRECT ANSWERS decompose the problem into steps
int searchedValue = 42;
int pos = 0;
boolean found = false;
while (pos < values.length && !found)
{
if (values[pos] == searchedValue)
{
found = true;
}
else
{
pos++;
}
}
When the loop finishes what does the value of the boolean variable found indicate?
CORRECT ANSWERS whether or not the value 42 was found in the array
Consider the following code snippet:
int[][] arr =
{
{ 1, 2, 3 },
{ 4, 5, 6 }
};
int val = arr[0][2] + arr[1][2];
System.out.println(val);
What is the output of the given code snippet on execution? CORRECT ANSWERS 9
Which statement is true about the code snippet below?
The benefits of buying summaries with Stuvia:
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
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
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 ElevatedExcellence. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $12.99. You're not tied to anything after your purchase.