Computer Science A Test

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What is printed to the console? System.out.println(404 / 10 * 10 + 1);

401

Which of the following are valid logical operators? Select all that apply. -!= -&& -|| -== -> -~ -! -<

&&,||,!

Which of the following are valid arithmetic operators in Java? Select all that apply. -+ -** - - -* -% -x -&& -! -|| -/

+,-,*,%,/

Consider the following code segment. String a = /* some user input */; String b = /* some more user input */; How can I tell if these two Strings are equivalent?=

a.equals(b)

Consider the following code segment. String s1 = "apcsa"; String s2 = s1.toUpperCase(); System.out.println(s1); System.out.println(s2); What will be printed to the console?

apcsa, APCSA

Every program needs a main method, and it needs to be declared very specifically. What is the method signature for the main method? Remember, capitalization matters.

public static void main(String[] args)

What is the difference between a null String and an empty String?

An empty String is one whose length is 0. A null String is one that doesn't exist.

When (James Gosling, Dennis Ritchie, Bjarne Stroustrup) created the Java programming language, he was working as an engineer at (Bell Labs, Sun Microsystems, Oracle). After a buyout, Java is now owned and maintained by (Bell Labs, Sun Microsystems, Oracle)

James Gosling, Sun Microsystems, Oracle

Consider the following program. import java.lang.Scanner; public class Quiz { public static void main(String[] args) { Scanner in = new Scanner(System.in); /* do whatever you're going to do with the scanner */ in.close(); } } Why won't my code compile?

The Scanner is defined in the util package, not the lang package.

Consider the following program, which is in a file called HelloWorld.java. public class Hello { public static void main(String[] args) { System.out.println("Hello, world!"); } } Why won't my code compile? -The name of the class and the name of the file must match exactly. -The keyword public on the first line should be capitalized. -The keyword static on the second line should be capitalized. -This code will successfully compile.

The name of the class and the name of the file must match exactly.

I've written a complex section of code in my program. I want to add a few sentences describing my logic. public class Complex { public static void main(String[] args) { int i = 1; String s = "This part is simple."; String x = "This next part is not so simple."); ...pretend there is lots ...and lots of complex ...code right here } } I know I don't need any Javadoc comments, but I'm not sure how to add regular comments. What are some suitable ways to do this? Select all that apply. -/* // Here are a few sentences. They are meant to // explain what I did here. */ -/* * Here are a few sentences. They are meant to * explain what I did here. */ -/** * Here are a few sentences. They are meant to * explain what I did here. */ -// Here are a few sentences. They are meant to // explain what I did here.

/* * Here are a few sentences. They are meant to * explain what I did here. */, // Here are a few sentences. They are meant to // explain what I did here.

If I wanted to indicate the author of a Java class in a Javadoc comment, how would I do this? -/* * Ryan Wilson is the @author of this class. */ -/** * @author Ryan Wilson */ -/* * @author Ryan Wilson */ -/** * Ryan Wilson is the @author of this class. */

/** * @author Ryan Wilson */

Consider the following sequence of commands. $ pwd /Users/rwilson/Desktop $ mkdir APCSA $ cd APCSA $ mkdir hello-world $ cd hello-world $ cd ../.. $ pwd <unknown-output> What is the value of <unknown-output>? -/Users/rwilson/Desktop -/Users/rwilson/Desktop/APCSA/hello-world -/Users/rwilson/Desktop/APCSA -This will result in an error.

/Users/rwilson/Desktop

Consider the following sequence of commands. $ pwd /Users/rwilson/Desktop/ $ cd APCSA $ cd hello-world $ pwd <unknown-output> What is the value of <unknown-output>? -/Users/rwilson/Desktop/hello-world/ -/APCSA/hello-world/ -/Users/rwilson/Desktop/APCSA/hello-world/ -/Users/rwilson/Desktop/APCSA

/Users/rwilson/Desktop/APCSA/hello-world/

Consider the following code segment. int x = 5; int y = 2; int z = x / y; System.out.println(z); What will be printed to the console?

2

Consider the following code segment. int x; x = 5 - 4 + 9 * 12 / 3 - 10; What is the value of x after the code segment is executed? -13 - -10 - -57 -27 -30

27

How many primitive data types does the Java programming language provide? -4 -6 -8 -10

8

Why did the creators of Java choose to lean so heavily on the syntax of C and core features of C++? -C and C++ were the only available languages at the time from which to draw inspiration. -C and C++ were tremendously popular at the time, and the creators of Java sought to capitalize on their popularity. -C and C++ were near-perfect languages, so why not? -The creators of Java wished to highlight what they believed were neglected and overlooked languages.

C and C++ were tremendously popular at the time, and the creators of Java sought to capitalize on their popularity.

Which two programming languages were a major influence on the design, structure, and syntax of Java? Objective-C C# BASIC C++ Python JavaScript FOTRAN C

C++ C

When your program is finished using a Scanner, what should you do?

Close it.

Assume that a and b are boolean variables that have been initialized. Consider the following code segment. a = a && b; b = a || b; Which of the following statements is always true? I. The final value of a is the same as the initial value of a. II. The final value of b is the same as the initial value of b. III. The final value of a is the same as the initial value of b.

II only

Which of the following consumer electronics were originally targeted by the creators of Java? -Smart cars -Microwaves -Remote controls -Cell phones -Tablets -Computers -Interactive TVs

Microwaves, Remote Controls, Interactive TVs

You run the ___ command when you want to upload changes to Github, and run the ___ command when you want to download changes from Github

Push, Pull

Which of the following primitive data types are responsible for storing integer values? Select all that apply. -short -number -long -int -float -integer -double -byte

Short, long, int, byte

There are three types of comments in Java. What are they? -Field comments -Method comments -HTML comments -Class comments -Single-line comments -Multi-line comments -Javadoc comments

Single-line comments, Multi-line comments, Javadoc comments

Which of the following is not a tenet originally published in a white paper by James Gosling? Select all that apply. -Multithreaded -Distributed -Static -Dynamic -Object-Oriented -Secure -Loosely Typed

Static, Loosely Typed

Which of the following is the most correct way to achieve the following. -Declare a single variable to store my first and last name. -Declare a single variable to store my current GPA. -Initialize the variable storing my name with an empty string. -Initialize the variable storing my GPA to 0.0. You can assume the code segments below are properly housed in a class and method. -String str = ""; double x = 0.0; -String fullName; double gpa; fullName = ""; gpa = 0.0; -String fullName = "Mr. Wilson"; double gpa = 4.0; -name = ""; gpa = 0.0;

String fullName; double gpa; fullName = ""; gpa = 0.0;

I need to print a portion of a String to the console. That portion needs to include everything except the first and last two characters of the original. You may assume the following code has already been written for you. String original = /* some user input */; System.out.println(substring); -String substring = original.substring(2, original.length() - 1); -String substring = original.substring(1, original.length() - 2); -String substring = original.substring(2, original.length() - 2); -String substring = original.substring(2);

String substring = original.substring(2, original.length() - 2);

Consider the following code segment. double x = 123456.789 I want to print x with the appropriate group separators (i.e., commas), and only display two values after hte decimal. How can I do this?

System.out.printf("%,.2f", x);

Consider the following code segment. double x = 123.456789; I want to print x, but only display three values beyond the decimal. How can I do this?

System.out.printf("%.3f", x);

Consider the following code segment. systemout.printl(Hello, world!") What is the correct version of this line? -system.out.println("Hello, world!"); -System.out.println("Hello, world!"); -System.out.println("Hello, world!); -Systemout.println("Hello, world!");

System.out.println("Hello, world!");

I want to add a comment (but not a Javadoc comment!) at the end of a print statement. System.out.println("Hello, world"); <-- I want my comment here! What might this look like? Select all the apply. -System.out.println("Hello, world"); # here is a comment -System.out.println("Hello, world"); // here is a comment -System.out.println("Hello, world"); /** here is a comment */ -System.out.println("Hello, world"); /* here is a comment */

System.out.println("Hello, world"); // here is a comment, System.out.println("Hello, world"); /* here is a comment */

Consider the following code segment. import java.util.Scanner; public class Quiz { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("How old are you?"); int age = in.nextInt(); in.close(); } } And consider the following usage. $ javac Quiz.java $ java Quiz How old are you? Twenty. Why is my program crashing?

The user entered a a word when the program expected an integer.

Consider the following sequence of commands. $ pwd /Users/rwilson/Desktop $ cd APCSA $ cd hello-world -bash: cd: hello-world: No such file or directory $ What is the likely cause of this error? -There is no cd command. -No error occurred. -There is no hello-world folder in the APCSA folder. -The APCSA folder is corrupted.

There is no hello-world folder in the APCSA folder

What is the practical difference between the following two code segments? // A int x = 43; x += 7; System.out.println(x); // B int x = 43; x = x + 7; System.out.println(x);

These two code segments are identical

How are comments interpreted and used by the compiler? -The compiler uses them to try to optimize our code. -The compiler uses them to generate error messages for compilation failures. -They aren't. Comments are strictly for human consumption.

They aren't. Comments are strictly for human consumption.

What are the three stages a file can be in when working with a Git repository? -Newly created files -Untracked files -Modified files -Unmodified files -Changes to be committed -Changes not staged for commit

Untracked files, Changes to be committed, Changes not staged for commit

Assume that k, m, and n have been declared and correctly initialized with int values. Consider the following statement. boolean b1 = (n >= 4) || ((m == 5 || k < 2) && (n > 12)); Which of the statements below represents the logical opposite of b1? -boolean b2 = (n >= 4) && ((m == 5 && k < 2) || (n > 12)); -boolean b2 = (m == 5 || k < 2) && (n > 12); -boolean b2 = (n < 4) || ((m != 5 || k >= 2) && (n <= 12)); -boolean b2 = (n == 4); -boolean b2 = (n < 4) && (m != 5 && k >= 2) || (n <= 12);

boolean b2 = (n < 4) && (m != 5 && k >= 2) || (n <= 12);

Assume that x and y are properly initialized variables. (x && y) && !(x || y) Which of the following best describes the result of evaluating the expression above? -true always -false only when x and y have the same value -false always -true only when x and y have different values -true only when x is true and y is true

false always

The following code segment will not compile. final int MAX = 10; MAX = 15; Why not? -MAX isn't designed to store data of that type. -This code will compile. -final variables cannot be changed once initialized. -MAX was not declared before trying to re-assign its value.

final variables cannot be changed once initialized.

I'm getting ready to start a Problem Set 0, and I need to download the skeleton repository. Which command(s) can I run from the terminal to do this? Select all that apply. -git init -git push origin master -git clone [email protected]:ap-java-ucvts/pset-0-skeleton.git -git clone [email protected]:ap-java-ucvts/pset-0-skeleton.git pset-0 -git commit -m "initial commit"

git clone [email protected]:ap-java-ucvts/pset-0-skeleton.git, git clone [email protected]:ap-java-ucvts/pset-0-skeleton.git pset-0

Consider the following sequence of commands. $ git remote add origin [email protected]:ap-java-ucvt/quiz.git I mistyped the URL. I forgot the s at the end of ucvts in the username. How can I fix my mistake? Select all the apply. -git remote set-url origin [email protected]:ap-java-ucvts/quiz.git -git remote delete origin [email protected]:ap-java-ucvts/quiz.git git remote add origin [email protected]:ap-java-ucvts/quiz.git -git remote remove origin git remote add origin [email protected]:ap-java-ucvts/quiz.git -git remote add origin [email protected]:ap-java-ucvts/quiz.git

git remote remove origin git remote add origin [email protected]:ap-java-ucvts/quiz.git

After initializing a Git repository, I've made a few changes to a few different files. It's been a few days, though, and I can't remember what files I changed. How can I find out? -git commit -m "what files did I change?" -git status -git push origin master -git add

git status

Which of the following is a primitive data type in Java? Select all that apply. -bool -Scanner -triple -String -long -byte -double -float -char -int -boolean -short

long, byte, double, float, char, int, boolean, short

I'm working in the terminal and I want to see all of the files and folders in the current directory. Which command should I run? -pwd -cd parentFolder -clear -ls

ls

Although the compiler ignores whitespace, people should not. Consider the following program, which is syntactically correct. It will compile and run, but it's ugly to look at. public class HelloWorld{ public static void main(String[] args) {System.out.println("Hello, world!");}} Stylistically, which of the following are acceptable version of this program? Choose all the apply. -public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world!"); } } -public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world!"); } } -public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world!"); } } -public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world!"); } } -public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world!"); } }

public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world!"); } }, public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world!"); } }


संबंधित स्टडी सेट्स

3.13: Unit Test: How important Ideas are Expressed

View Set

Abeka Spanish I Test 9 (quarter exam)

View Set

Microeconomics Chapter 9,10,11,12,13,14, Exam Review

View Set

Behavior and the Brain Chapter 1-5

View Set

Smartbook Pre-Topic Readings Topic 2a Blood

View Set

med surg chapter 66 caring for clients with burns

View Set

Social Class & Mobility (Exam #2)

View Set