1/262
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Check which of the following are examples of computational thinking. Mark all that apply.
Mapping out a trip to Florida
Choosing the movie to watch at the cinema
Deciding what to wear to the prom
Check which of the following are examples of computational thinking. Mark all that apply.
Choosing a college
Shopping for a car
All of the following are included in the the process of computational thinking except
Coding
Check which of the following are examples of computational thinking. Mark all that apply.
Shopping for a bicycle
Planning what to do with friends on the weekend
Baking a cake
Scenario: Consider operating a car as part of a computer program. Turning the key to start a car is a form of
Abstraction
Consider the following code segment.
System.out.println("How many chucks\n");
System.out.print("could a woodchuck chuck\n");
System.out.print("if a woodchuck could chuck ")
System.out.print("wood?");
What is printed as a result of executing the code segment? Choose the best answer.
Nothing - compiler error
Consider the following code segment.
System.out.println("\"Observe good faith and justice \ntoward all nations.\"");
System.out.print("George Washington");
What is printed as a result of executing the code segment? Choose the best answer.
"Observe good faith and justice
toward all nations."
George Washington
Consider the following code segment.
System.out.println("What we");System.out.println("think, we become.");System.out.print("Buddha");
What is printed as a result of executing the code segment? Choose the best answer.
What we
think, we become.
Buddha
Consider the following code segment.
System.out.print("count down");System.out.print(4);System.out.print(3);System.out.print(2);System.out.print(1);System.out.print(" liftoff!");
What is printed as a result of executing the code segment? Choose the best answer.
count down4321 liftoff!
Consider the following code segment.
System.out.print("Oh, what fun");System.out.print(" it is")System.out.print(" to learn Java!");
What is printed as a result of executing the code segment? Choose the best answer.
Nothing - compiler error
Consider the following code segment.
System.out.print("Oh, ");System.out.println("happy");System.out.print("happy");System.out.print("day!");
What is printed as a result of executing the code segment? Choose the best answer.
Oh, happy
happyday!
Consider the following code segment.
System.out.print("a");System.out.println("b");System.out.print("c");System.out.print("d");
What is printed as a result of executing the code segment? Choose the best answer.
ab
cd
Consider the following code segment.
System.out.print("\"Yesterday you said tomorrow.\n");System.out.print("Just do it.\"\n");System.out.print("- Nike");
What is printed as a result of executing the code segment? Choose the best answer.
"Yesterday you said tomorrow.
Just do it."
- Nike
Consider the following code segment.
System.out.print(5);System.out.print(4);System.out.print(3);System.out.print(2);System.out.print(1);System.out.print(" liftoff!");
What is printed as a result of executing the code segment? Choose the best answer.
54321 liftoff!
54321liftoff!
54321 liftoff!
54321Liftoff!
54321 liftoff!
Consider the following code segment.
System.out.print('count down');System.out.print("4");System.out.print("3");System.out.print("2");System.out.print("1");System.out.print(" liftoff!");
What is printed as a result of executing the code segment? Choose the best answer.
54321liftoff!
54321 liftoff!
Nothing - compiler error
54321liftoff!
54321 liftoff!
Consider the following code segment where x is a local variable:
int x;System.out.println(x);
What would be the output? (Choose the best answer.)
None, runtime error
x
None, Compiler error
0
None, Compiler error
In Java, boolean information can be...
zero or one
true or false
any number
all of these
true or false
Of the following declarations, which are declared properly? Choose all that apply.
String set = "on ready";
char go = "F"
boolean ready = false;
char go = 'F';
String set = "on ready";
boolean ready = false;
char go = 'F';
What is the size in bytes for a long data type?
8
4
1
2
8
Of the following declarations, which are declared properly? Choose all that apply.
String a = null;
String c = "a";
String d = "happy";
String b = "";
String a = null;
String c = "a";
String d = "happy";
String b = "";
What is the default value of a boolean data type?
false
empty
0
true
false
What can be stored in a char data type?
true
'A'
"aa"
"name"
'A'
What is the default value of a double data type?
0.0
0
empty
1
0.0
In Java, boolean information can be...
zero or one
any number
true or false
all of these
true or false
Given the following declarations:
int i = 12; short s = 35;long m = 50;float f = 2.5f;double d = 0.25;
Show the value that will be stored in the variable on the left after the expression below is executed. If it shows an error, just type error.
f = i * 2;
24.0
What is the default value of an int data type?
empty
0
0.0
1
0
Which value below falls within the range of an int? Choose all that apply.
1,000,000
1
0
1,000,000,000,000
1,000,000
1
0
Which value below falls within the range of an short? Choose all that apply.
1000
0
100
130
1000
0
100
130
What is the size in bytes for a short data type?
2
1
8
4
2
A code segment (not shown) is intended to determine the number of players whose average score in a game exceeds 0.5. A player's average score is stored in avgScore, and the number of players who meet the criterion is stored in the variable count.
Which of the following pairs of declarations is most appropriate for the code segment described?
double avgScore;boolean count;
int avgScore;int count;
double avgScore;double count;
double avgScore;int count;
double avgScore;
int count;
Consider the following code segment.
System.out.print("One"); // Line 1System.out.print("Two"); // Line 2System.out.print("Three"); // Line 3System.out.print("Four"); // Line 4
The code segment is intended to produce the following output, but does not work as intended.
OneTwoThreeFour
Which of the following changes can be made so that the code segment produces the intended output?
Changing print to println in line 1 only
Changing print to println in lines 1, 2, 3, and 4
Changing print to println in line 2 only
Changing print to println in line 3 only
Changing print to println in line 2 only
In this course, to gather input for a user, we used a class from the Java APi named the ____________ class.
Scanner
Scan
Input
Sc
Scanner
Consider the following code segment.
System.out.print("");System.out.println("");System.out.println("*");System.out.print("***");
What is printed as a result of executing the code segment?
**********
**********
**********
**********
***
***
****
Consider the following code segment.
System.out.print(); // Line 1System.out.print(""); // Line 2System.out.println(); // Line 3System.out.println("*"); // Line 4
The code segment is intended to produce the following output, but may not work as intended.
***
Which line of code, if any, causes an error?
Line 3
Line 4
The code segment works as intended
Line 2
Line 1
Line 1
Consider the following code segment.
System.out.print(5);System.out.print(4);System.out.print(3);System.out.print(2);System.out.print(1);System.out.print(" liftoff!");
What is printed as a result of executing the code segment? (Choose the best answer.)
54321liftoff!
5 4 3 2 1 liftoff!
54321 liftoff!
54321 Liftoff!
THIS ONE IS THE CORRECT ONE IF SHOWN BEFORE
54321 liftoff!
Consider the following code segment.
System.out.print("AP");System.out.println();System.out.println("CS");System.out.print("A");
What is printed as a result of executing the code segment?
APCSA
APCSA
AP CSA
APCSA
AP
CS
A
Consider the following code segment.
import java.util.Scanner public class Test { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter your name:" ); String name = input.nextLine(); System.out.print("Hello, " name); }}
What will be the output if the user enters Jack?
Hello Jack
Hello, Jack
There is a compiler error because input is a keyword and we cannot use it as a variable
There is a compiler error because there is no concatenation operator to join "Hello" and the value of name.
There is a compiler error because there is no concatenation operator to join "Hello" and the value of name.
Consider the following code segment.
System.out.print(I do not fear computers. ); // Line 1System.out.println(I fear the lack of them.); // Line 2System.out.println(--Isaac Asimov); // Line 3
The code segment is intended to produce the following output but may not work as intended.
I do not fear computers. I fear the lack of them.--Isaac Asimov
Which change, if any, can be made so that the code segment produces the intended output?
In line 1, print should be changed to println.
In lines 2 and 3, println should be changed to print.
In lines 1, 2, and 3, the text that appears in parentheses should be enclosed in quotation marks.
No change is needed; the code segment works correctly as is.
In lines 1, 2, and 3, the text that appears in parentheses should be enclosed in quotation marks.
Consider the following code segment.
System.out.print("Hello System.out.println");System.out.print("!!!");
What is printed as a result of executing the code segment?
Hello System.out.println!!!
Hello!!!
Nothing is printed because the text "System.out.println" cannot appear inside a print statement.
Hello !!!
Hello System.out.println!!!
If an int variable age holds the value 5, what is its value after the following statement is executed?
age = age * 4;
If it shows an error, just type error.
20
Which of the following expressions evaluate to 4 ?
I. 7+ 10 % 13II. (7 + 10) % 13III. 6 - 2 % 13
II & III only
I & II only
I only
I, II, & III
II & III only
What is the result of 19 % 5 when evaluated in a Java expression?
If it shows an error, just type error.
4
What is the result of 13 / 4 when evaluated in a Java expression?
If it shows an error, just type error.
3
What would be the output of the following code?
int x = 110;int y = 3;x %= y;System.out.println(x);
5
2
107
3
2
x and y are declared as integer variables.You are given the following expression:
x >= y
Which of these expressions is the opposite of the above expression and has valid syntax?
x < y
There's not enough information to determine this.
x =< y
x <= y
x == y
x < y
If an int variable weight currently holds the value 150, what is its value after the following statement is executed?
weight -= 27;
If it shows an error, just type error.
123
What will be printed after the following statements are executed?
int length;length = 11; // 11length = 3; length = length;length /= 50;System.out.println(length);
If it shows an error, just type error.
21
If an int variable weight currently holds the value 150, what is its value after the following statement is executed?
weight -= 27;
If it shows an error, just type 'error.'
123
Assume that you are given the following declarations:
int num = 0;double val = 0.0;num = 9 % 6 / 4 - 4;
Show the value that will be stored in the variable on the left. If the expression causes an error, just type 'error.'
-4
What is the result of
17 % 5
when evaluated in a Java expression?
If it shows an error, just type 'error.'
2
Assume that you are given the following declarations:
int num = 0;double val = 0.0;num = 2 % 6 / 2 - 4;
Show the value that will be stored in the variable on the left. If the expression causes an error, just type 'error.'
-3
What will be printed after the following statements are executed?
int length;length = 11; // 11length = 3; length = length;length /= 50;System.out.println(length);
If it shows an error, just type error.
21
What would be the output of the following code?
int input = 5;int output = 3;input++;output += input;System.out.println(output);
9
10
11
12
9
If an int variable age holds the value 4, what is its value after the following statement is executed?
age = age * 7;
If it shows an error, just type 'error.'
28
What would be the output of the following code?
int x = 10;int y = 5;x %= y;System.out.println(x);
0
10
1
5
0
Consider the following code segment, which is intended to print the digits of the two-digit int number num in reverse order. For example, if num has the value 53, the code segment should print 35. Assume that num has been properly declared and initialized.
/ missing code /
System.out.print(onesDigit);System.out.print(tensDigit);
Which of the following can be used to replace / missing code / so that the code segment works as intended?
int onesDigit = num % 10;int tensDigit = num / 10;
int onesDigit = num / 10;int tensDigit = num % 10;
int onesDigit = 10 / num;int tensDigit = 10 % num;
int onesDigit = num % 100;int tensDigit = num / 100;
int onesDigit = num % 10;
int tensDigit = num / 10;
Assume that you are given the following declarations:
int num = 0;double val = 0.0;val = 11 % 6 / 2.0 - 1;
Show the value that will be stored in the variable on the left. If the expression causes an error, just type 'error.'
1.5
Which of the following returns the correct average when 3 values had been added to an integer total?
(double) total / 3;
(double) (total / 3);
(int) total / 3;
total / 3;
(double) total / 3;
Given the following code segment, what is the value of b when it finishes executing?
double a = 9.6982;int b = 12;b = (int) a;
9.6982
10
12
9
9
Given the following declarations:
int i = 15; short s = 25;long m = 50;float f = 2.5f;double d = 0.25;
Show the value that will be stored in the variable on the left after the expression below is executed. If it shows an error, just type error.
f = 3.14;
0.5357143
Assume that you are given the following declarations:
int num;double val;val = 17 / 2.0 + 4;
Show the value that will be stored in the variable on the left. If the expression causes an error, just type 'error'.
12.5
Which of the following returns the correct average when 3 values had been added to an integer total?
(double) total / 3;
total / 3;
(double) (total / 3);
(int) total / 3;
(double) total / 3;
Given the following declarations:
int i = 15; short s = 25;long m = 50;float f = 2.5f;double d = 0.25;
Show the value that will be stored in the variable on the left after the expression below is executed. If it shows an error, just type error.
m = i + 1;
16
The following code is illegal. Rewrite the code using an integer cast to make it legal.
double d = 187.2;int j = d;
int j = 187.2;
double d = d + 187.2;
int j = (int) d;
int double d = 187.2;
int j = (int) d;
Given the following declarations:
int i = 15; short s = 25;long m = 50;float f = 2.5f;double d = 0.25;
Show the value that will be stored in the variable on the left after the expression below is executed. If it shows an error, just type error.
i = f * 2;
5.0
Given the following declarations:
int i = 15; short s = 25;long m = 50;float f = 2.5f;double d = 0.25;
Show the value that will be stored in the variable on the left after the expression below is executed. If it shows an error, just type error.
f = (float) 3.14;
3.14
Consider the following code segment
int count = 5;double multiplier = 2.5;int answer = (int) (count multiplier);answer = (answer count) % 10;System.out.println(answer);What is printed as a result of the code segment?
0.5
2.5
12.5
0
0
Given the following declarations:
int i = 15; short s = 25;long m = 50;float f = 2.5f;double d = 0.25;
Show the value that will be stored in the variable on the left after the expression below is executed. If it shows an error, just type error.
i = s + 1;
26
Given the following declarations:
int i = 15; short s = 25;long m = 50;float f = 2.5f;double d = 0.25;
Show the value that will be stored in the variable on the left after the expression below is executed. If it shows an error, just type error.
i = (int) m + 1;
51
What makes a constant in Java?
The keyword constant
The keyword final
The keyword static
Writing it in all capitals
The keyword final
Given the following declarations:
int i = 15; short s = 35;long m = 50;float f = 2.5f;double d = 0.25;
Show the value that will be stored in the variable on the left after the expression below is executed. If it shows an error, just type error.
i = s + 3;
38
If an integer variable diameter currently holds the value 5, what is its value after the following statement is executed?
diameter = diameter * 4;
If it shows an error, just type error.
20
What is the default value of an int data type?
empty
0.0
1
0
0
What would be the output of the following code?
int x = 10;int y = 5;x %= y;System.out.println(x);
1
5
10
0
0
What would be the output of the following code?
int x = 110;int y = 3;x %= y;System.out.println(x);
2
5
107
3
2
What would be the output of the following code?
int x = 10;int y = 5;x--;y += x;System.out.println(y);
15
14
12
11
14
Consider the following code segment, which is intended to print the digits of the two-digit int number num in reverse order. For example, if num has the value 53, the code segment should print 35. Assume that num has been properly declared and initialized.
/ missing code /
System.out.print(onesDigit);System.out.print(tensDigit);
Which of the following can be used to replace / missing code / so that the code segment works as intended?
int onesDigit = num % 10;int tensDigit = num / 10;
int onesDigit = 10 / num;int tensDigit = 10 % num;
int onesDigit = num / 10;int tensDigit = num % 10;
int onesDigit = num % 100;int tensDigit = num / 100;
int onesDigit = num % 10;
int tensDigit = num / 10;
Which of the following expressions evaluate to 4?
7+ 10 % 13
(7 + 10) % 13
6 - 2 % 13
1
1 and 2
2 and 3
All (1, 2, and 3)
2 and 3
Given the following declarations:
int i = 15; short s = 25;long m = 50;float f = 2.5f;double d = 0.25;
Show the value that will be stored in the variable on the left after the expression below is executed. If it shows an error, just type error.
i = s + 1;
26
Question 172 / 2 pts
Given the following declarations:
int i = 15; short s = 25;long m = 50;float f = 2.5f;double d = 0.25;
Show the value that will be stored in the variable on the left after the expression below is executed. If it shows an error, just type error.
d = f * i + 1;
38.5
Given the following declarations:
int i = 15; short s = 25;long m = 50;float f = 2.5f;double d = 0.25;
Show the value that will be stored in the variable on the left after the expression below is executed. If it shows an error, just type error.
s = (short)5;
5
The following code is illegal. Rewrite the code using an integer cast to make it legal.
double d = 187.2;int j = d;
double d = d + 187.2;
int j = 187.2;
int j = (int) d;
int double d = 187.2;
int j = (int) d;
What specifies the behavior of objects in a Java class?
methods
class
object
attributes
methods
Consider the following code. What would be the output?
public class Question { private int num = 20; public static void main(String args[]) { Question q1 = new Question(); System.out.println(q1.num); }}
20
Nothing output; compiler error
q1.num
"20"
20
You can only have one constructor method in your class.
True
False
false
A programmer has created an Employee class. The class contains variables to represent the following.
A String variable called name to represent the name of the employee
An int variable called age to represent the age of the employee
A String variable called gender to represent the gender of the employee
A String variable called race to represent the race of the employee
The object person will be declared as type Employee.
Which of the following descriptions is accurate?
An attribute of the person object is name.
An instance of the Employee object is person.
An instance of the person class is Employee.
An attribute of the age object is int.
An attribute of the person object is name.
Which of the following is a proper constructor method for a Train class?
public Train() { };
public class Train() { };
public String Train() { };
private Train() { };
public Train() { };
What is the correct way to create an object with the reference variable fluffy of the Cat class?
new Cat fluffy;
Cat new = Cat fluffy();
Cat fluffy = Cat();
Cat fluffy = new Cat();
Cat fluffy = new Cat();
A class has a default constructor when it is first created.
True
False
true
A student has created a Person class. The class contains variables to represent the following:
A String variable called name to represent the name of a Person object
An int variable called age to represent the age of a Person object
A String variable called gender to represent the gender of a Person object
The object is declared as type Person and has the reference variable p1. Which of the following descriptions is accurate?
An attribute of the Person object is String.
An instance of the Person class is name.
An attribute of the Person instance is p1.
An attribute of the Person instance is age.
An attribute of the Person instance is age.
A student has created a Cat class. The class contains variables to represent the following:
A String variable called breed to represent the breed of a Cat object
An int variable called age to represent the age of a Cat object
A String variable called name to represent the name of a Cat object
The object is declared as type Cat and has the reference variable pet. Which of the following descriptions is accurate?
An instance of the pet class is Cat.
An instance of the Cat class is pet.
An attribute of the name object is String.
An attribute of the Cat instance is pet.
An instance of the Cat class is pet.
What are the data or properties for an object in Java?
attributes
methods
object
class
attributes
Consider the following method.
public double oneMethod(int a, boolean b) { / implementation not shown / }
Which of the following lines of code, if located in a method in the same class as oneMethod, will compile without error?
double result = oneMethod(0, false);
int result = oneMethod(2, false);
double result = oneMethod(2.5, true);
int result = oneMethod(2.5, true);
double result = oneMethod(0, false);
When you write a method, the heading is always in the following order:
method name - return type - parameters
return type - method name - parameters
parameters - return type - method name
the order doesn't matter
return type - method name - parameters
Consider the following method.
public void doSomething() { System.out.println("Let's do something!");}
Each of the following statements appears in a method in the same class as doSomething().
Which of the following statements are valid uses of the method doSomething()?
doSomething();
String output = doSomething();
System.out.println(doSomething());
I and II only
II only
I and III only
I only
I only
Consider the following methods, which appear in the same class.
public int function1(int i, int j) { return i + j;}public int function2(int i, int j) { return j - i;}
Which of the following statements, if located in a method in the same class, will initialize the variable x to 11?
int x = function2(3, 1) + function1(4, 5);
int x = function2(4, 5) + function1(1, 3);
int x = function1(3, 1) + function2(4, 5);
int x = function1(4, 5) + function2(1, 3);
int x = function1(4, 5) + function2(1, 3);
Consider the following methods, which appear in the same class.
public void slope(int x1, int y1, int x2, int y2) { int xChange = x2 - x1; int yChange = y2 - y1; printFraction(yChange, xChange);}public void printFraction(int numerator, int denominator) { System.out.print(numerator + "/" + denominator);}
Assume that the method call slope(1, 2, 5, 10) appears in a method in the same class. What is printed as a result of the method call?
2/1
8/4
5/1
4/8
8/4
Consider the following method.
public double myMethod(int a, boolean b){ / implementation not shown / }
Which of the following lines of code, if located in a method in the same class as myMethod, will compile without error?
double result = myMethod(0, false);
int result = myMethod(2.5, true);
double result = myMethod(true, 10);
int result = myMethod(2, false);
double result = myMethod(0, false);
Consider the following method.
public void doSomething() { System.out.println("Something has been done");}
Each of the following statements appears in a method in the same class as doSomething. Which of the following statements are valid uses of the method doSomething?
doSomething();
String output = doSomething();
System.out.println(doSomething());
I only
I, II, and III
I and III
I and II
I only
Consider the following method.
public double oneMethod(int a, boolean b){ / implementation not shown / }
Which of the following lines of code, if located in a method in the same class as oneMethod, will compile without error?
double result = oneMethod(false, 1);
int result = oneMethod(9.2, false);
double result = oneMethod(10, true);
int result = oneMethod(22, false);
double result = oneMethod(10, true);