100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
CPSC 1110 Questions With Verified Solutions $12.99   Add to cart

Exam (elaborations)

CPSC 1110 Questions With Verified Solutions

 0 view  0 purchase
  • Course
  • CPSC 1110
  • Institution
  • CPSC 1110

CPSC 1110 Questions With Verified Solutions

Preview 2 out of 11  pages

  • November 7, 2024
  • 11
  • 2024/2025
  • Exam (elaborations)
  • Questions & answers
  • CPSC 1110
  • CPSC 1110
avatar-seller
ElevatedExcellence
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

What is the output of the following code snippet?

int[] values = { 10, 20, 30, 7};
int[] numbers = values;
numbers[2] = 24;
values[3] = numbers[0] + 6;
System.out.println (numbers[2] + " " + numbers[3] + " " + values[2] + " " + values[3]);
CORRECT ANSWERS 24 16 24 16

What is the output of the following statements?

ArrayList<String> names = new ArrayList<String>();
names.add("Bob");
names.add(0, "Ann");
names.remove(1);
names.add("Cal");
names.set(2, "Tony");
for (String s : names)
{
System.out.print(s + ", ");
} CORRECT ANSWERS array list bound error

Assume the method doSomething has been defined as follows:

public static void doSomething (int[] values)
{
for (int i = 1; i < values.length; i++)
{
values[i - 1] = values[i];

, }
}
What does the method do? CORRECT ANSWERS It moves each element of the array
values to a lower index position and overwrites the first element.

What is the output of the following code snippet?

int[] values = { 1, 2, 3, 4};
values[2] = 24;
values[values[0]] = 86;
for (int i = 0; i < values.length; i++)
{
System.out.print (values[i] + " ");
} CORRECT ANSWERS 1 86 24 4

Consider the code snippet below:

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

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 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.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

81113 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
$12.99
  • (0)
  Add to cart