100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
AP Computer Science Exam Review 2024 Questions and Answers $13.49   Add to cart

Exam (elaborations)

AP Computer Science Exam Review 2024 Questions and Answers

 9 views  0 purchase
  • Course
  • AP Computer Science
  • Institution
  • AP Computer Science

AP Computer Science Exam Review

Preview 4 out of 37  pages

  • July 30, 2024
  • 37
  • 2023/2024
  • Exam (elaborations)
  • Questions & answers
  • AP Computer Science
  • AP Computer Science
avatar-seller
millyphilip
AP Computer Science Exam Review
Which of the following is a valid string in Java?
A. "a"
B. "@#$"
C. "hello"
D. "123"
E. All - Answer -E. All
To output:
HelloThere
You would need to use:
System.out._____ ("Hello");System.out.print("There");
A. Print
B. println
C. None of the options shown
D. Println
E. print - Answer -B. println
________ is the process of finding and eliminating errors in code. - Answer -Debugging
What will happen if the computer fails to compile your code? - Answer -An error message will be displayed
Which of the following would Java interpret as being a String?
A. ```Hello World```
B. <p>Hello World</p>
C. `Hello World`
D. "Hello World"
E. 'Hello World' - Answer -D. "Hello World"
What is the name for the type of data that consists of characters enclosed in double quotes, such as "Hello world!"? - Answer -String
A collection of characters in quotes is a __________ - Answer -String What will be displayed if the following Java code segment is run?
System.out.print("one ");
System.out.println("two ");
System.out.print("three ");
A. one two three
B. one two three
C. one two three
D. one two three - Answer -A. one two three
Which of the following would Java recognize as a String?
A. "4b0ut T!me"
B. "word"
C. "!@*"
D. "45"
E. ALL - Answer -E. ALL
Strings are defined by __________ quotes - Answer -double
What is wrong with the following code?
String x;
System.out.println(x);
A. You cannot print the string without first assigning a value
B. You cannot assign x as a variable name
C. The line, System.out.println(x); should instead be System.out.println(x.toString()).
D. The line, String x; will cause an error because it should be string x.
E. System.out.println()should be replaced with system.out.print() - Answer -A. You cannot print the string without first assigning a value
What is wrong with the following code?
Scanner input = new Scanner(System.in);
String s = nextLine();
A. Nothing is wrong, that code won't generate any errors.
B. Should be: String s = input.next;
C. Should be: String s = input.nextLine();
D. Should be: String s = next();
E. nextLine() method can't work with String variables - Answer -C. Should be: String s = input.nextLine(); Which of the following is a legal variable name in Java?
A. app counter
B. 2values
C. int
D. value
E. a.name - Answer -D. value
Suppose we had declared a String variable called greetString in a program. Which of the following lines would assign this variable to contain the String "Greetings! Nice to meet you"?
A. greetString : "Greetings! Nice to meet you";
B. let greetString = "Greetings! Nice to meet you"
C. greetString = "Greetings! Nice to meet you";
D. "Greetings! Nice to meet you" = greetString;
E. String greetString "Greetings! Nice to meet you" - Answer -C. greetString = "Greetings! Nice to meet you";
What will be printed to the screen when the following code runs?
String str1 = "one";
String str2 = "nine";
System.out.print(str1 + str2)
A. onenine
B. Nothing will be printed. We need to use double quotes in the print statement.
C. nineone
D. ten - Answer -A. onenine
The following code is to be used to get the favorite meal of a user.
Scanner scan = new Scanner(System.in);
String favoriteMeal;
System.out.println("Enter your favorite meal for dinner: ");
/* missing line */
Which of the following should go in the place of /* missing line */ to get this input from the user and store it in the variable favoriteMeal?
A. scan.nextLine();
B. favoriteMeal = nextLine();
C. scan.nextLine(favoriteMeal);
D. favoriteMeal = scan.nextLine(); - Answer -D. favoriteMeal = scan.nextLine();
Suppose the variable "greeting" is used to store a String below:
String greeting = "Hello there,";
Which of the following will print "Hello there, user"?
A. System.out.println("greeting user");
B. System.out.println(greeting + " user"); C. System.out.println(greeting)(" user");
D. System.out.println(greeting - "user"); - Answer -B. System.out.println(greeting + " user");
To declare a String variable name and set it equal to "Lillian" you would type:
A. String name = "Lillian";
B. String name = new "Lillian";
C. string name = "Lillian";
D. name = "Lillian"; - Answer -A. String name = "Lillian";
Which line of code correctly declares and initializes the variable x to a value of 3?
A. Integer x = new Integer(x);
B. x = 3
C. int x = 3;
D. int x : 3; - Answer -C. int x = 3;
Different data types can store different amounts of data. In the options below, which has
the data types listed in order, from largest to smallest?
A. double, String, boolean, int
B. All the data types are the same size.
C. int, String, double, boolean
D. String, double, int, boolean
E. int, double, boolean, String - Answer -D. String, double, int, boolean
What data type should you use to hold whether a person passed or failed a class?
A. boolean
B. int
C. double
D. String - Answer -A. boolean
Long is a data type that is ... longer... than an integer. It still is able to store whole numbers, but reserves a larger space in memory so that it can store a larger value.
What is the largest value you can store in a variable that has the long data type?
A. 2,147,483,647
B. 256
C. 1,024
D. 9,223,372,036,854,775,807 - Answer -D. 9,223,372,036,854,775,807
Consider the following code:
long y = 9223372036854775807L;
y = y + 1;
System.out.println(y);
What number does the program print when compiled and run? Hint: think about the max
value you just looked up in your previous answer.
A. -1

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 $13.49. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

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