APCS Midterm Study Guide

Ace your homework & exams now with Quizwiz!

What does the following line of code print out to the console? System.out.println("\"\\ / \\\\ // \\\\\\ ///\"");

"\/\\//\\\///"

Look at the following use of the substring() method: String word = "Hello World!"; String subs = word.substring(1,2); The String subs will contain:

"e"

What value is stored in result if: int result = 10 - 2 % 2;

10

Refer to the following code fragment: double answer = 12 / 7; System.out.println("12 / 7 = " + answer); The output is

12 / 7 = 1.0

Refer to the following method. public static int mystery(int n) { if (n == 1) return 3; else return 3 * mystery(n - 1); } What value does mystery(1) return?

3

Read the following excerpt from the Syllabus to answer the following question: Homework: Everybody learns in different ways and at different speeds; in general though, if you're an average student and want to receive an average (C-B) grade, you should plan on spending about 7 hours each week outside of class in addition to the five hours of classroom time. If you have difficulty with the material, or if you want to receive an A in the course, you'll probably have to spend more time. If an average student wants to end up with an average B or C in this course, how much time should the student spend working on Java outside of class in addition to the 5 hours per week in the classroom? B. One hour each day, six days a week.

5...7

Suppose x = 2 and y = 3. If the statement x *= y; is executed once, what is the value of x?

6

What is the output of the following code segment? int myAge = 63; int kathysAge = myAge; kathysAge = 60; System.out.print(myAge);

63

Each memory cell has a unique location in main memory, called the _________.

Address

Read the following excerpt from the Syllabus to answer the following question: Because the class relies on doing your homework before class, you can't really succeed by staying up all night every Sunday. Instead, you need to budget your time. Spend at least 30 minutes every day, reading the material, and 30 minutes in the computer lab, or on your computer at home, working on problems. For most students, the best way to learn to program is to actually write programs. Spend time writing and running small "demo" programs to explore the behavior of what you are learning. The homework readings and programming assignments are outlined in the schedule. Feel free to work ahead. Since the schedule clearly outlines the homework due dates, there is no reason to turn in 'late work'. The best way to learn Java is to:

All of the above

Evaluate the following expression. Make sure that your answer is correct type. For instance, if the answer is 2 and the type is int, then you should enter 2. If the answer is 2, and the type is double, then enter 2.0. 13 + Math.abs(-7) - Math.pow(2.0, 3) + 4

Answer: 16.0

Evaluate the result from evaluating the following integer expression. Make sure that your answer is the correct type. For instance, if the answer is 2 and the type is int, then you should enter 2. If the answer is 2, and the type is double, then enter 2.0. 26 % 10 % 4 * 2

Answer: 4

Evaluate the result from evaluating the following integer expression. Make sure that your answer is the correct type. For instance, if the answer is 2 and the type is int, then you should enter 2. If the answer is 2, and the type is double, then enter 2.0. (12 + 4) / 4 * 2

Answer: 8

Programs that are designed to "work for you", carrying out a task you specify, are known as:

Application programs

The elements inside the class body are surrounded with, or delimited by:

Braces {}

What does the following code fragment print to the console? System.out.println("C:\\Windows\\my.ini\\");

C:\windows\my.ini\

What's the result of the following code snippet? public static void main(String[ ] args) { double bottles; double bottles_volume = bottles * 2; System.out.println(bottle_volume); }

Compile-time error

When a Java string does not have surrounding double quotes, what type of error occurs?

Compile-time error

Consider the method public String mystery(String s) { String s1 = s.substring(0,1); String s2 = s.substring(1, s.length() - 1); String s3 = s.substring(s.length() - 1); if (s.length() <= 3) return s3 + s2 + s1; else return s1 + s2 + s3; } What is the output of System.out.println(mystery("DELIVER"));

DELIVER

Which of these must appear outside the body of a class?

Import statements

The devices that feed data and programs into computers are called ______.

Input devices

Which of the following variable names is an example of a constant?

MILES_PER_HOUR

What is the computer component that stores program instructions during a program execution?

Memory

The statement System.out.print("No" + "2 + 3" + "way"); produces the output:

No2 + 3way

The statement System.out.print ("No" + (2 + 3) + "way"); produces the output:

No5way

When will the result be equal to 3? public static int whatIsIt(int x, int y) { int result = 0; if (x > y) result = 4; else result = 3; return result; }

Only when x <= y

In a main method definition, the symbols appearing inside the ( ) are called the:

Parameter list

If your java source code program compiles, but displays an error message when you run it, then it must have a:

Runtime error

Which of the following statements correctly creates a Scanner object for keyboard input?

Scanner keyboard = new Scanner(System.in);

The following line of code is going to print out what type of value? System.out.print("575");

String

Which of the following is not a primitive data type?

String

In the assignment statement below, what is the purpose of the (double) ? int x = 3, y = 2; double z = (double) x / y;

To make sure that the result of the division is a decimal number.

Based on the code below: String sentence; String str1, str2, str3; int length1, length2; sentence = "Today is Wednesday."; str1 = sentence.substring(9, 18); str2 = str1.substring(0, 3); str3 = sentence.replace('d', '*'); length1 = sentence.length(); length2 = str1.length(); System.out.print(str3);

To*ay is We*nes*ay

True or False: All of the following statements are true. In Java, 12 % 5 and 12 / 5 have the same answer. The names int and double describe the type of variable being initialized or declared. ANSWER:

True

What is the output of the following Java code? int x = 0; if(x < 0) System.out.print("One "); System.out.print("Two "); System.out.print("Three");

Two Three

Which of these is a legal (that is, syntactically correct) Java class name?

U2

Text, like everything else in your computer, is stored as raw binary numbers. To treat those numbers as characters, they must be encoded. The encoding scheme used in Java is called:

Unicode

Given two strings, a and b, return the result of putting them together in the order abba, e.g. "Hi" and "Bye" returns "HiByeByeHi". EXAMPLES: makeAbba("Hi", "Bye") → "HiByeByeHi" makeAbba("Yo", "Alice") → "YoAliceAliceYo" makeAbba("What", "Up") → "WhatUpUpWhat" public String makeAbba(String a, String b) { String result = ""; result = _________________ return result; } What would result need to be in order to finish this function?

a + b + b +a

If a, b, and c are integers, which of the following conditions is sufficient to guarantee that the expression a < c || a < b && !(a == c) evaluates to true?

a < c

Define: Define Concatenation operator. What is the name of the following Scanner object? Scanner cin = new Scanner(System.in); ANSWER:

cin

Which one of the following is a correct method of declaring and initializing an double variable with name crossett?

double crossett = 30;

True or False: The following statement, written in the interactions pane, will compile and print to the console. System.out.println("said Sally. "I've said so." See?);

false

Response Feedback: The keyword public is called the access specifier and determines who has access to the method. The modifier static is normally only used when the method needs to be called from the main() method. The word void represents the return type of the method. The word void indicates that the method doesn't calculate a value, but carries out an action instead. The word printTopHalf is the method name, which is used to call it. The parentheses following the name are called the parameter list. Since there are no parameters, the list is empty. The body of the method is surrounded with braces on the subsequent lines. When you define the procedure, create a ______________ for each value you want to pass into the procedure.

formal parameter

The programmer intends the output to be 12 / 7 = 1.7142857142857142 Which of the following replacements for the first line of code will not fix the problem?

int answer = (12 / 7);

Which of the following code fragments will cause an error?

int luckyNumber; System.out.println(luckyNumber);

Consider the following method definition: public static void printTopHalf() { } The word static :

is needed if the method is called from main()

Response Feedback: The parentheses ensure that the number 2 and 3 are added before concatenation "pastes" the result together. In Java, Scanner is a class in which package?

java.util

Here is a portion of the source code for a computer program: 69 6D blah blah blah blah 2A 3B....................................... 61 77 so on a so forth This program is an example of

machine language.

Which of these words that can appear in a Java program are not a reserved word? *Hint: It does not show up in blue text in Dr. Java.

out

Write the method main heading: It must be exactly as Java needs it to be for your code to compile.

public static void main(String[] args)

Response Feedback: Since this is the two-argument version of substring(), it returns a new String beginning at position 1 (that is, the second character in the original String, since Strings begin at 0), and going up to, but not including the character at index position 2. When defining a function, (unlike a procedure), you must specify a ____________.

return type

Consider the following code segment: if (n != 0 && x / n > 100) statement1; else statement2; If n is of type int and has a value of 0 when the segment is executed, what will happen?

statement2, but not statement1, will execute

Refer to the following code fragment below: public String yourName = "Kevin"; The name yourName refers to:

the name of the variable.

In a variable definition, the kind of value stored inside is called its:

type


Related study sets

Catcher in the Rye Vocabulary (4-7)

View Set

Area of Triangle, Square, Rectangle, Parallelogram and Circle

View Set

Insurance Terms and Related Concepts

View Set

Module 6: Do We Form Accurate Impressions of Others?

View Set

Planning and Strategic Management

View Set

BA 323 CH:5 time value of money hw problems

View Set

3 - Life Insurance Policies - Provisions, Options and Riders Part B

View Set