100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
COSC 101 - Final Exam Study (Fall 2024) Questions and Answers $14.99   Add to cart

Exam (elaborations)

COSC 101 - Final Exam Study (Fall 2024) Questions and Answers

 5 views  0 purchase
  • Course
  • COSC
  • Institution
  • COSC

COSC 101 - Final Exam Study (Fall 2024) Questions and Answers

Preview 4 out of 56  pages

  • August 24, 2024
  • 56
  • 2024/2025
  • Exam (elaborations)
  • Questions & answers
  • COSC
  • COSC
avatar-seller
millyphilip
COSC 101 - Final Exam Study (Fall 2024)
Questions and Answers
Which of the following data types can store real numbers? (select all that apply).
[] char
[] double
[] String
[] int
[] Float
[] Integer - Answer -[] char
∎ double
[] String
[] int
∎ Float
[] Integer

If I have a Scanner declared as myScanner, myScanner.next() will read an entire line of
input and save it as a string.
[] True
[] False - Answer -[] True
∎ False

public static void main(String[] args) {
int val = 100;
System.out.print(val++);
}
What is printed to the screen given the code above? - Answer -100

What is output from the following code?
String s = "Georgia Tech";
String s1 = s.substring(0,7);
String s2 = s1.substring(2);
String s3 = s2.substring(0,3);
System.out.println(s3);
[] eorg
[] orgi
[] eor
[] org
[] You will get an index out of bounds exception - Answer -[] eorg

,[] orgi
[] eor
∎ org
[] You will get an index out of bounds exception

public static void main(String[] args) {
double data = 1.25512;
String out = String.format("%.2f", data);
System.out.print(out);
}
What is printed to the screen in the code above? - Answer -1.26

Which of the following would equal 2?

I.
int x = 0;
x ++;
x += x;

II.
int y = 4;
y ++;
y /= 2;

III.
int z = 4;
z += 2;
z /= 2;

[] I only
[] II only
[] III only
[] I, II, and III
[] I and II only - Answer -[] I only
[] II only
[] III only
[] I, II, and III
∎ I and II only

What will be printed after the following code executes?
double d;
{
d = 24;
int e = 6;
}
System.out.print(d + e + " " + d/6);

,[] 24.0 6 4.0
[] 30.0 4.0
[] 24 6 4.0
[] 24 6 4
[] The code will not execute because of a compilation error - Answer -[] 24.0 6 4.0
[] 30.0 4.0
[] 24 6 4.0
[] 24 6 4
∎ The code will not execute because of a compilation error

A field with the ________ keyword means that the field cannot be changed after being
set once. - Answer -final

Given the following java code, give the full name of the file including the extension (an
extension for a Microsoft Word file is .docx, a PDF file is.pdf, etc).

public class addition {
public static void main(String[] args) {
int x = 5;
int y = 6;
int sum;

sum = x + y;
System.out.println(sum);
}
}

Full name of file: - Answer -addition.java

There is a method called checkString that determines whether a string is the same
forwards and backwards. The following data set inputs can be used for testing the
method. What advantage does Data Set 2 have over Data Set 1?
Data Set 1 Data Set 2
aba bcb
abba bcd
aBa

[] Data Set 2 contains fewer values than Data Set 1
[] Data Set 2 contains one string which should return true and one that should return
false.
[] All strings in Data Set 2 have the same number of characters.
[] The strings in Data Set 2 are all lowercase
[] There are no advantages - Answer -[] Data Set 2 contains fewer values than Data Set
1

, ∎ Data Set 2 contains one string which should return true and one that should return
false.
[] All strings in Data Set 2 have the same number of characters.
[] The strings in Data Set 2 are all lowercase
[] There are no advantages

Consider the following Cat class, with the cat's age stored in the age attribute. The
getAge method is intended to allow methods in other classes to access a Cat object's
age value; however, it does not work as intended. Which of the following best explains
why the getAge method does NOT work as intended?

public class Cat
{
private int age;

public Cat(int a)
{
age = a;
}

public int getAge()
{
return a;
}
}


[] The return type of the getAge method should be void.
[] The getAge method should be declared private.
[] The variable age is not declared inside the getAge method.
[] The instance variable age should be returned instead of a, as a is local to the
constructor.
[] The getAge method should have at least one parameter. - Answer -[] The return type
of the getAge method should be void.
[] The getAge method should be declared private.
[] The variable age is not declared inside the getAge method.
∎ The instance variable age should be returned instead of a, as a is local to the
constructor.
[] The getAge method should have at least one parameter.

A student has created a Cat class. The class contains variables to represent the
following.

- A String variable called color to represent the color of the cat
- A String variable called breed to represent the breed of the cat
- An int variable called age to represent the age of the cat

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 millyphilip. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $14.99. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

82215 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

Recently viewed by you


$14.99
  • (0)
  Add to cart