1/103
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No study sessions yet.
In Java, there are only 8 primitive data types.
True
The int data type is capable of storing floating-point numbers.
False
The int variable uses the sane amount of space as a double variable.
False
The equals sign (=) is known as the assignment operator.
True
The compiler will ignore indentation that appears in the middle of a word.
False
Java, include statements are used to gain access to libraries outside of default Java Library.
False
Given the following class header
public class MoonWeight {...}
for the following program MoonWeight to compile, it must be saved in which of the following files?
MoonWeight.java
Which of the following statements is a valid variable declaration statement?
int x;
Which of the following operators has the highest precedence?
/ and *
In Java, the expression (3/4) + 7.0 evaluates to
7.0
In Java, the expression (12/3.0) * (1/2) evaluates to
0.0
Which of the following number literals is invalid in Java?
2,700
In Java, every variable data type is either a primitive data type or a(n)
Object
Which of the following is not a primitive data type?
String
Given the following Scanner object:
Scanner input = new Scanner (System.in);
Which of the following methods can be used to obtain a string from the user?
input.nextLine();
Java sets aside certain key words that have a special meaning or action known as
Reserved words
Which of the following is an invalid user-defined symbol?
-void
-lucky7
-PILLOWS
-None of the above
-void
Which of the following is an invalid user-defined symbol?
-First_name
-1time <--- Answer
-$income
-None of the above
-1time
Camel casing is a naming convention in which
Multiple words are combined and uppercase letters are used to distinguish words.
Which of the following symbols is used to enclose a string literal?
None of the above
A multi-line comment begins with the symbol or /*.
Which of the following symbols mark the end of a multi-line comment?
*/
What is printed as a result of executing the following code segment?
double x = 2;
SOP("x + x");
x + x
What is printed as a result of executing the following code segment?
int x = 3;
SOP("Total: " + x + 4.0);
Total: 7.0
πr^2
Which of the following Java expressions can be used to evaluate the above arithmetic expression?
Math.pow(r, 2) * Math.PI
|x| + √x
Which of the following Java expressions can be used to evaluate the above arithmetic expression?
None of the above
A syntax error is also known as
compile-time error
One (1) bit is comprised of eight (i) bytes
False
ENIAC, one of the world's first electronic computers, used transisters in order to store and process data
True
Lossless compression should be used when loss of information could pose a problem. Such as with text documents + spreadsheets
True
The jpeg image format uses lossy compression to reduce the file size of images
True
Which of the following can be represented by a single binary digit?
B. The remainder when dividing a whole # by 2
C. The value of a Boolean value
A computer program uses 3 bits to represent integers. When the program adds the decimal (base 10) numbers 5+3, the result is 0. Which of the following is the best explanation for the result.
An overflow error occurred
What ASCII character is represented by the binary (base 2) number 1001010?
J
Digital images are often represented by red, green, & blue values of each individual pixel in the image. A photographer is manipulating a digital image and overwriting the original image. Which of the following describes lossless transformation of the digital image?
C. Creating the negative of an image by creating a new RGB triplet for each pixel in which each value is calculated by subtracting the original value from 255. The negative of an image is reversed from the original; light areas appear dark and colors are reversed.
______ invented the e-machine, helped break the Enigma code during WW2 and wrote a paper that is considered the foundation of Computer Science
Alan Turing
______ is the observation that, over the history of computing hardware, the # of transistors in a dense integrated circuit has doubled approx every 2 years.
Moore's Law
(Pseudocode) Which of the following Boolean exprssions are equivalent to the epxression num >= 15 (select 2)
B. (num > 15) or (num = 15)
C. (NOT (num < 15)
Which of the following digital storage units has the largest capacity?
Terabyte
(Pseudocode) In the program below, the initial value of x is 5 and the initial value of y is 10
C. November
Which of the following is not a logical operator?
!=
Which of the following changes will NOT affect the results when the code segment is executed?
1: IF (a=0)
2: {
3: b <- a + 10
4: }
5: else
6: {
7: b <- a + 20
8: }
Changing line 3 <- 10
What is printed to the user if he/she enters a time of 8?
int ware = 8;
int time = input.nextInt();
if (ware < time)
{
System.out.println("Get out of bed! You're late!");
}
System.out.println("Have a good day!");
B. Have a good day!
What is printed to the user?
boolean snowDay = true;
if (!snowDay)
System.out.println("Stay Inside!");
System.out.println("The weather outside is frightful!");
B. The weather outside is frightful!
What is printed to the user if he/she enters a yr of 1999?
int year = input.nextInt();
if (year <= 1999)
{
System.out.println("Let's drive!");
}
else
{
System.out.println("Wait a big longer...");
}
System.out.println("Age check complete.");
A. Let's Drive
Age Check Complete
Which of the following Java expression is equivalent to the algebraic expression 3 < x <= 6
A. x <= 6 && X > 3
What is printed if the user enters 60?
int speed = intput.nextInt(); // get speed from user
if (speed <= 60) {
System.out.println("Safe travels!");
} else if (speed < 65) {
System.out.println("Slow down! Be careful!");
} else if (speed > 65) {
System.out.println("Caught speeding!")
}
Safe travels!
What is printed if the user enters 64?
int speed = intput.nextInt(); // get speed from user
if (speed <= 60) {
System.out.println("Safe travels!");
} else if (speed < 65) {
System.out.println("Slow down! Be careful!");
} else if (speed > 65) {
System.out.println("Caught speeding!")
}
Slow down! Be careful!
What is printed if the user enters 65?
int speed = intput.nextInt(); // get speed from user
if (speed <= 60) {
System.out.println("Safe travels!");
} else if (speed < 65) {
System.out.println("Slow down! Be careful!");
} else if (speed > 65) {
System.out.println("Caught speeding!")
}
None of the above (nothing is printed)
Given:
int x = 7;
Which of the following expression will trigger short-circuit evaluation?
A: x != 7 && x < 10
The expression !(x < 1 && x >= 10) is equivalent to which of the following expression?
x >= 1 || x < 10
Given the following program:
public class Vote
{
public static void main(String[] args)
{
int age = 20;
if (age >= 18)
{
System.out.println("Can vote.");
} // A
else
{
System.out.println("Can't vote");
} // B
} // C
} // D
The scope of the variable age ends with which brace?
A: C
(Pseudocode) The code fragment below is intended to display "add" if the positive num is add.
IF (
{
DISPLAY("add")
}
Which of the following can be used to replace
A: (num MOD 2) = 1
String is one of the 8 primitive data types
False
The process of "adding" Strings together is known as concatenation
True
The last index in a non-empty String is always one less than its length
True
The String IDE documents all of the information needed to work with String objects including a complete list of methods
False (It's API)
What is printed?
String lj = "Leeroy Jenkins!";
boolean result = lj.equals("leeroy jenkins!");
System.out.println(result);
False
Which of the following set of symbols is used to construct a String literal?
" "
Given: String thg = "I volunteer as tribute";
Which of the following expressions makes a comparison between two characters?
thg.charAt(2) == 'v'
Which of the following String methods is overloaded?
substring and indexOf
Consider the following method signature:
String :: my Method(int) :: boolean
What data type does the above method return?
boolean
Given: String movie = "The Imitation Game";
Which of the following method calls would cause a StringIndexOutOfBoundsException?
none
What is printed:
String nums = "4321";
if (nums.length() % 2 == 0)
System.out.println(nums.charAt(1));
else
System.out.println(nums.charAt(2));
3
What is printed:
String hulk = "Hulk Smash";
String output = "";
for (int i=0; i
uk Sah
What is printed:
String sport = "football";
String output = "";
for (int i=0; i
fotbal
What is printed:
String horrible = "What a crazy random happenstance";
char c = horrible.charAt(2)
for (int i=horrible.length(); i >=0; i--)
if (horrible.charAt(i) == c)
System.out.print("cray");
none (IndexOutOfBoundsException)
What is printed:
Srring joker = "Why so serious?";
String output = "";
for (int i=joker.length()-1; i<=0; i--)
if (joker.charAt(i) != 'i')
output += joker.charAt(i);
System.out.println(output);
?suores os yhW
Given:
String fma = "Edward Elric";
Which of the following method calls returns "Elric"?
fma.substring(7); and fma.substring(7,fma.length());
What is printed:
String lulu = "That tasted purple!";
String temp = lulu.substring(1, lulu.length()-1);
String out.println(temp);
hat tasted purple!
What is printed:
String str = "Thrones";
System.out.println(str.substring(str.length / 2));
ones
What is printed:
String str = "Surprised Pikachu";
System.out.println(str.substring(3).indexOf("P");
7
What is printed:
String str = "yoyo";
String output = "";
for (int i=0; i
yoyooyoyoo
What is printed:
String greeting = "Hello, World!";
System.out.println(greeting.indexOf("o"));
4
Given:
String str = "Fire and Blood!";
System.out.println(
Which could replace missing code and cause code segment to print -1?
str.indexOf("b");
What is printed:
String str = "tall door bell";
String output = "";
for (int i=0; i
tal dorbe
What is printed:
String winter = "Happy Holla Days!";
int i = winter.indexOf("a");
while (i >= 0)
{
System.out.print(i);
winter = winter.substring(i+1);
i = winter.indexOf("a");
}
182
The following code should print "that wasnt very cash money of you" for every character that is not a '$'. Which of the following should replace missing code so that the code works as intended?
String str = "$Godzilla$";
for (int i=0; i
System.out.println("That wasnt very cash money of you");
str.charAt(i) != '$'
The following code segment should print every other character from str for example, if str <-- "xoxoxo", the code segment would print "xxx". Which of the following should replace
String str = "They did surgery on a grape."";
String rtn = "";
for(int i = 0; i < str.length(); i++)
if (
rtn += str.charAt(i);
SOP(rtn);
i % 2 == 0
x-- is functionally equivalent to x = x-x
False
The body of a while-loop will always execute at least once time
False
The second statement in the header of a for-loop is the loop's condition
True
The braces that indicate the body of a loop can be ommitted if the loop contains only 1 statement
True
An IOException is a compile-time (syntax) error
False
The expression i++ is equivalent to which of the following statement?
1) i = i + 1
2) i = 1 + 1
3) i += 1
1 and 3 only
Which of the following is not an assignment operator?
=-
Which is printed by the following code fragment?
int x = 3;
x *= 3;
x /= 4;
System.out.println(x);
2
A single execution of the loop's body is known as which of the following?
Iteration
(Psudocode) Consider the following code segment:
j <- 1
Repeat until (
{
j < j *2
}
j = 6
What is printed by the following code segment?
int count = 1;
while (count < 7)
{
if (count % 2 != 0)
System.out.print(count);
count++;
}
135
What is printed by the following code segment?
int x = 15;
int count = 1;
while (count <= x)
{
if (x % count == 0)
{
System.out.print(count);
x -= count;
}
count += 1;
}
1239
What is printed by this following code segment?
int c=0;
while (c < 6)
{
System.out.print(c + "+" + c);
c++;
}
0+01+12+23+34+45+5
Consider the following code fragment:
int i=12;
while (i>0)
{
if (i % 2 != 0)
{
i = i - 3;
}
i--;
}
System.out.println(i);
-1
Programs I and II below are each intended to calculate the sum of the integers from 1 to n. Assume that n is a positive integer (e.g. 1,2,3...)
Program I:
i <- 1
result <- 0
REPEAT n TIMES
{
result <- result + i
i <- i + 1
}
DISPLAY(result)
Program II:
i <- n
result <- 0
REPEAT n TIMES
{
result <- result + i
i <- i - 1
}
DISPLAY(result)
Which of the following best describes the behavior of the 2 programs?
Both program I and program II displays the correct sum
Consider the following code fragment:
int sum = 0;
int outer = 1;
while (outer <= 2)
{
int inner = 1;
while (inner <= outer)
{
sum += inner;
inner++;
}
outer++;
}
System.out.println(sum);
What is printed as a result of executing the coding segment?
4
What is printed by the following code segment?
for (int i=0; i <=8; i++)
{
if (i % 2 = 0)
System.out.println(i);
}
2
4
6
8
Consider the following code fragment:
boolean q = false;
int x = 10;
for (int i=0; i
x -= i;
else
System.out.print(q);
System.out.print(x)
if (x % 3 == 0)
i++;
}
10961
Consider the following code segment:
i <- 1
counter <- 1
REPEAT UNTIL (
{
DISPLAY(i)
i <- i * 2
counter <- counter + 1
}
Which of the following replacements for
counter < 10
(Pseudocode) You want to simulate rolling two six-sided dice. You are interested in how often you see a sum of 7 on the two dice. Which of the following would simulate counting the number of times one would see a sum of 7 on two dice rolls when rolling the dice 25 times?
Note that RANDOM(x,y) returns a random number in the range of [x,y]
q <- 0
REPEAT 25 TIMES
{
a <- RANDOM(1,6) + RANDOM(1,6)
IF (a = 7)
q <- q + 1
}
DISPLAY(q)
and
q <- 0
REPEAT 25 TIMES
{
a <- 0
REPEAT 2 TIMES
a <- a + RANDOM(1,6)
IF (a = 7)
q <- q + 1
}
DISPLAY(q)
Given that n and count are both of the same int, which statement is true about the following code
for (count = 1; count <= n; count++)
SOP(count);
count = 1;
while (count <= n)
{
SOP(count);
count++;
}
I and II are exactly equivalent for all input values n.
When reading from a file, which of the following scanner methods can be used as a condition of a loop as it returns true if there is more information in the file to be read?
hasNext