Podcast
Questions and Answers
What is the data type of the following literal?
"fooled you"
What is the data type of the following literal? "fooled you"
String
What is the camel case variable name for a variable that represents the top score?
What is the camel case variable name for a variable that represents the top score?
topScore
What are the three primitive data types that will be tested on the AP Exam?
What are the three primitive data types that will be tested on the AP Exam?
What is the camel case variable name for a variable that represents a shoe size?
What is the camel case variable name for a variable that represents a shoe size?
Signup and view all the answers
What data type should you use to represent the average grade for a course?
What data type should you use to represent the average grade for a course?
Signup and view all the answers
What data type should you use for a shoe size like 8.5?
What data type should you use for a shoe size like 8.5?
Signup and view all the answers
What data type should you use to record if it is raining or not?
What data type should you use to record if it is raining or not?
Signup and view all the answers
What is the data type of the following literal?
'A'
What is the data type of the following literal? 'A'
Signup and view all the answers
What data type holds true/false values?
What data type holds true/false values?
Signup and view all the answers
What data type should you use to represent the amount of money in a bank account?
What data type should you use to represent the amount of money in a bank account?
Signup and view all the answers
Which of the following is NOT the name of a Java primitive data type?
Which of the following is NOT the name of a Java primitive data type?
Signup and view all the answers
What are the two varieties of data in Java?
What are the two varieties of data in Java?
Signup and view all the answers
Which of the following is the correct header line for the main method in Java?
Which of the following is the correct header line for the main method in Java?
Signup and view all the answers
A ______ is a note written to a human reader of a program.
A ______ is a note written to a human reader of a program.
Signup and view all the answers
Which of the following will result in an error?
Which of the following will result in an error?
Signup and view all the answers
What are the two steps that take place when an assignment statement is executed?
What are the two steps that take place when an assignment statement is executed?
Signup and view all the answers
On a single line of code declare x, y, and z all to be an integer data type.
On a single line of code declare x, y, and z all to be an integer data type.
Signup and view all the answers
(2 - 6) / 2 + 9
(2 - 6) / 2 + 9
Signup and view all the answers
Which of the following is legal?
Which of the following is legal?
Signup and view all the answers
State what is printed.
int x = 40;
int y = 4;
System.out.println(2 + 8 * y / 2 - x);
State what is printed. int x = 40; int y = 4; System.out.println(2 + 8 * y / 2 - x);
Signup and view all the answers
What is the value of the expression:
-5 * 9 / 10 + 10 * 5 / 9
What is the value of the expression: -5 * 9 / 10 + 10 * 5 / 9
Signup and view all the answers
On a single line of code declare x, y, and z to be double and on that same line initialize them all to be 3.14.
On a single line of code declare x, y, and z to be double and on that same line initialize them all to be 3.14.
Signup and view all the answers
State what is printed.
int a = 100;
int b = 200;
b/=a;
System.out.println(b + 1);
State what is printed. int a = 100; int b = 200; b/=a; System.out.println(b + 1);
Signup and view all the answers
What is another way to write p = p - 1;?
What is another way to write p = p - 1;?
Signup and view all the answers
The following code stores a 20 in the variable num;
double num = 61/3;
What small change can you make to this single line of code to make it produce the "real" answer to the division?
The following code stores a 20 in the variable num; double num = 61/3; What small change can you make to this single line of code to make it produce the "real" answer to the division?
Signup and view all the answers
State what is printed.
System.out.println((double)(90/9));
State what is printed. System.out.println((double)(90/9));
Signup and view all the answers
Write code that will calculate and print the square root of 435.61.
Write code that will calculate and print the square root of 435.61.
Signup and view all the answers
Which of the following would return a random number from 1 to 6 inclusive?
Which of the following would return a random number from 1 to 6 inclusive?
Signup and view all the answers
What is the purpose of wrapper classes?
What is the purpose of wrapper classes?
Signup and view all the answers
Write a Java formula using the Math class for:
Distance = |val1 - val2|
Write a Java formula using the Math class for: Distance = |val1 - val2|
Signup and view all the answers
Evaluate:
Math.ceil(115.8)
Evaluate: Math.ceil(115.8)
Signup and view all the answers
Evaluate:
Math.abs(2 + -4)
Evaluate: Math.abs(2 + -4)
Signup and view all the answers
Evaluate:
Math.sqrt(16) * Math.max(Math.abs(-5), Math.abs(-3))
Evaluate: Math.sqrt(16) * Math.max(Math.abs(-5), Math.abs(-3))
Signup and view all the answers
The classes that convert primitives to objects are called _____ classes
The classes that convert primitives to objects are called _____ classes
Signup and view all the answers
Evaluate:
Math.min( 8, 3 + 2 )
Evaluate: Math.min( 8, 3 + 2 )
Signup and view all the answers
Write a formula that will find the distance between two values, num1 and num2 by taking the absolute value of their difference. Assign the answer to double x.
Write a formula that will find the distance between two values, num1 and num2 by taking the absolute value of their difference. Assign the answer to double x.
Signup and view all the answers
Evaluate:
Math.sqrt(76 + 45)
Evaluate: Math.sqrt(76 + 45)
Signup and view all the answers
Which of the following would return a random int from 1 to 10 inclusive?
Which of the following would return a random int from 1 to 10 inclusive?
Signup and view all the answers
What is the value of len after the following executes?
String s1 = "Love you!";
int len = s1.length();
What is the value of len after the following executes? String s1 = "Love you!"; int len = s1.length();
Signup and view all the answers
What is the value of str2 after the following code executes?
String s1 = "helicopter";
String s2 = s1.substring(4, 7);
What is the value of str2 after the following code executes? String s1 = "helicopter"; String s2 = s1.substring(4, 7);
Signup and view all the answers
Consider the following code segment.
String s1 = "Queen Mary";
String s2 = "1936 Queen Mary";
String s3 = "Queen Elizabeth";
System.out.print(s2.indexOf(s1) + " ");
System.out.println(s1.indexOf(s3));
What will be output when the code segment executes?
Consider the following code segment. String s1 = "Queen Mary"; String s2 = "1936 Queen Mary"; String s3 = "Queen Elizabeth"; System.out.print(s2.indexOf(s1) + " "); System.out.println(s1.indexOf(s3)); What will be output when the code segment executes?
Signup and view all the answers
What will be the value of r?
String r = "Saturday Night Live";
r = r.substring(5, 8);
What will be the value of r? String r = "Saturday Night Live"; r = r.substring(5, 8);
Signup and view all the answers
Consider the following code segment.
String s1 = "Djakarta";
String s2 = s1.substring(3, 7);
String s3 =s1.substring(3);
System.out.println(s2);
System.out.println(s3);
What will be output when the code segment executes?
Consider the following code segment. String s1 = "Djakarta"; String s2 = s1.substring(3, 7); String s3 =s1.substring(3); System.out.println(s2); System.out.println(s3); What will be output when the code segment executes?
Signup and view all the answers
Consider the following code segment.
String test = "This is a test.";
System.out.println(test.indexOf("is"));
What is printed as a result of executing the code segment?
Consider the following code segment. String test = "This is a test."; System.out.println(test.indexOf("is")); What is printed as a result of executing the code segment?
Signup and view all the answers
What is the output from the following code?
String s = "Computer Science is fun!";
String s1 = s.substring(0, 8);
String s2 = s1.substring(1);
String s3 = s2.substring(1, 3);
System.out.println(s3);
What is the output from the following code? String s = "Computer Science is fun!"; String s1 = s.substring(0, 8); String s2 = s1.substring(1); String s3 = s2.substring(1, 3); System.out.println(s3);
Signup and view all the answers
Consider the following code segment.
String str = "Hello World!";
System.out.println(str.length());
What is printed as a result of executing the code segment?
Consider the following code segment. String str = "Hello World!"; System.out.println(str.length()); What is printed as a result of executing the code segment?
Signup and view all the answers
Consider the following code segment.
String s1 = "A";
String s2 = "H";
System.out.print(s1.compareTo("B"));
System.out.print(" ");
System.out.println(s2.compareTo("B"));
What is printed as a result of executing the code segment?
Consider the following code segment. String s1 = "A"; String s2 = "H"; System.out.print(s1.compareTo("B")); System.out.print(" "); System.out.println(s2.compareTo("B")); What is printed as a result of executing the code segment?
Signup and view all the answers
Write a series of statements which acquires the length of name and stores it in a variable named len. You must first declare len.
String name = "SpongeBob SquarePants";
Write a series of statements which acquires the length of name and stores it in a variable named len. You must first declare len. String name = "SpongeBob SquarePants";
Signup and view all the answers
Examine this code:
String str = "Hello World!" ;
What is the index of the character 'e' ?
Examine this code: String str = "Hello World!" ; What is the index of the character 'e' ?
Signup and view all the answers
What sort of thing is "Happy Days" in the following:
String str = "Happy Days";
What sort of thing is "Happy Days" in the following: String str = "Happy Days";
Signup and view all the answers
What is returned by a method of type void?
What is returned by a method of type void?
Signup and view all the answers
New objects can be created by using the new operator with an appropriate constructor.
New objects can be created by using the new operator with an appropriate constructor.
Signup and view all the answers
What is the relationship between an object, method, and a class.
What is the relationship between an object, method, and a class.
Signup and view all the answers
Which of the following is equivalent to
!(a && (c < d))
Which of the following is equivalent to !(a && (c < d))
Signup and view all the answers
Consider the following declarations.
int valueOne, valueTwo;
Assume that valueOne and valueTwo have been initialized. Which of the following evaluates to true if valueOne and valueTwo contain the same value?
Consider the following declarations. int valueOne, valueTwo; Assume that valueOne and valueTwo have been initialized. Which of the following evaluates to true if valueOne and valueTwo contain the same value?
Signup and view all the answers
The boolean expression
!(A || B)
evaluates to
The boolean expression !(A || B) evaluates to
Signup and view all the answers
State what's printed:
int a = 84, a= 1;
boolean tf = true;
System.out.println(tf && !tf);
State what's printed: int a = 84, a= 1; boolean tf = true; System.out.println(tf && !tf);
Signup and view all the answers
Consider the following code segment which is intended to assign true to between if x is between lower and upper, inclusive, and false otherwise. Assume lower = lower) && (x = 90)isPassing = true;else if (testAverage >= 75 && assignmentsCompleted >= 4)isPassing = true;elseisPassing = false;II. boolean pass = false;if (testAverage >= 90)pass = true;else if (testAverage >= 75 && assignmentsCompleted >= 4)pass = true;isPassing = pass;III. isPassing = (testAverage >= 90) || (testAverage >= 75 && assignmentsCompleted >= 4);Which of the implementations will work correctly assuming that the variables have been initialized?
Consider the following code segment which is intended to assign true to between if x is between lower and upper, inclusive, and false otherwise. Assume lower = lower) && (x = 90)isPassing = true;else if (testAverage >= 75 && assignmentsCompleted >= 4)isPassing = true;elseisPassing = false;II. boolean pass = false;if (testAverage >= 90)pass = true;else if (testAverage >= 75 && assignmentsCompleted >= 4)pass = true;isPassing = pass;III. isPassing = (testAverage >= 90) || (testAverage >= 75 && assignmentsCompleted >= 4);Which of the implementations will work correctly assuming that the variables have been initialized?
Signup and view all the answers
State what's printed:
int a = 84, b = 1;
boolean tf = true;
System.out.println((a != 1) || tf || (a == b));
State what's printed: int a = 84, b = 1; boolean tf = true; System.out.println((a != 1) || tf || (a == b));
Signup and view all the answers
What is output by the following code?
int a = 90, b = 8;
if( (ab) )
a = b;
System.out.println(b++);
What is output by the following code? int a = 90, b = 8; if( (ab) ) a = b; System.out.println(b++);
Signup and view all the answers
A teacher put three bonus questions on a test and awarded 5 extra points to anyone who answered all bonus questions correctly and no extra points otherwise. Assume that the boolean variables bonusOne, bonusTwo, and bonusThree indicate whether a student has answered the particular question correctly. Each variable was assigned true if the answer was correct and false if the answer was incorrect.
Which of the following code segments will properly update the variable grade based on a student's performance on the bonus questions?
I. if (bonusOne && bonusTwo && bonusThree)
grade += 5;
II. if (bonusOne || bonusTwo || bonusThree)
grade += 5;
III. if (bonusOne)
grade += 5;
if (bonusTwo)
grade += 5;
if (bonusThree)
grade +=5;
A teacher put three bonus questions on a test and awarded 5 extra points to anyone who answered all bonus questions correctly and no extra points otherwise. Assume that the boolean variables bonusOne, bonusTwo, and bonusThree indicate whether a student has answered the particular question correctly. Each variable was assigned true if the answer was correct and false if the answer was incorrect. Which of the following code segments will properly update the variable grade based on a student's performance on the bonus questions? I. if (bonusOne && bonusTwo && bonusThree) grade += 5; II. if (bonusOne || bonusTwo || bonusThree) grade += 5; III. if (bonusOne) grade += 5; if (bonusTwo) grade += 5; if (bonusThree) grade +=5;
Signup and view all the answers
Consider the following code segment.
int x = ;
int y = ;
boolean result = (x < y);
result = ( (x >= y) && !result );
Which of the following best describes the conditions under which the value of result will be true after the code segment is executed?
Consider the following code segment. int x = ; int y = ; boolean result = (x < y); result = ( (x >= y) && !result ); Which of the following best describes the conditions under which the value of result will be true after the code segment is executed?
Signup and view all the answers
The boolean expression
(A || B) && (!A || !B)
evaluates to
The boolean expression (A || B) && (!A || !B) evaluates to
Signup and view all the answers
Consider the following code segment. Assume value is an int.
if (value < 0) || value < 100)System.out.print("Not in range");
elseSystem.out.print("In range");
Consider the following code segments that could be used to replace the code.
I. if (value < 0){if (value > 100)System.out.print("Not in range"); elseSystem.out.print("In range");}elseSystem.out.print("In range");II. if (value < 0)System.out.print("Not in range"); else if (value < 100)System.out.print("Not in range");elseSystem.out.print("In range");III. if (value >= 0)System.out.print("In range"); else if (value b && b > c) if (b < a) b = -b; else a = -a;else if (a > b || b > c) if (a < c) c = -c; else if (! (c > b)) b = -a;Which of the implementations will work correctly assuming that the variables have been initialized?
Consider the following code segment. Assume value is an int. if (value < 0) || value < 100)System.out.print("Not in range"); elseSystem.out.print("In range"); Consider the following code segments that could be used to replace the code. I. if (value < 0){if (value > 100)System.out.print("Not in range"); elseSystem.out.print("In range");}elseSystem.out.print("In range");II. if (value < 0)System.out.print("Not in range"); else if (value < 100)System.out.print("Not in range");elseSystem.out.print("In range");III. if (value >= 0)System.out.print("In range"); else if (value b && b > c) if (b < a) b = -b; else a = -a;else if (a > b || b > c) if (a < c) c = -c; else if (! (c > b)) b = -a;Which of the implementations will work correctly assuming that the variables have been initialized?
Signup and view all the answers
Consider the following code.
if (value < 0 || value > 100)System.out.println("true");elseSystem.out.println("false");
Given that value is an integer, which of the following code segments would have the same output as the code above?
Consider the following code. if (value < 0 || value > 100)System.out.println("true");elseSystem.out.println("false"); Given that value is an integer, which of the following code segments would have the same output as the code above?
Signup and view all the answers
Consider the following code segment.
int result= 99;
if (num1 == num2) {result = 0:}
else if (num1 > num2) {result = 1;}
else {result = -1;}
System.out.println(result);
Which of the following code segments will print the same result as the code above no matter what integers are stored in num1 and num2?
Consider the following code segment. int result= 99; if (num1 == num2) {result = 0:} else if (num1 > num2) {result = 1;} else {result = -1;} System.out.println(result); Which of the following code segments will print the same result as the code above no matter what integers are stored in num1 and num2?
Signup and view all the answers
Consider the following code segment.
int x = int n = 100;if (x < 1000){ if (x > 1000) n = 200; else n = 300;}else{ if (x < 1000) n = 400; else n = 300;}System.out.println(n);What is printed as a result of executing the code segment?
Consider the following code segment. int x = int n = 100;if (x < 1000){ if (x > 1000) n = 200; else n = 300;}else{ if (x < 1000) n = 400; else n = 300;}System.out.println(n);What is printed as a result of executing the code segment?
Signup and view all the answers
Show the basic skeleton of an if - else structure.
Show the basic skeleton of an if - else structure.
Signup and view all the answers
What is output by the following?
int x = 8, y = 5;
if( !(x == y) )
{ System.out.println("Sunday, Monday");}
else
{ System.out.println("Happy Days!");}
What is output by the following? int x = 8, y = 5; if( !(x == y) ) { System.out.println("Sunday, Monday");} else { System.out.println("Happy Days!");}
Signup and view all the answers
Write a single statement that will store a true in the boolean variable tf only if boo is negative.
Write a single statement that will store a true in the boolean variable tf only if boo is negative.
Signup and view all the answers
Determine the output of the following code segments. Write no output if there is no output.
int i = 2;
int j = 3;
if (j + 9 == i)
{ System.out.println ("You got it!");}
Determine the output of the following code segments. Write no output if there is no output. int i = 2; int j = 3; if (j + 9 == i) { System.out.println ("You got it!");}
Signup and view all the answers
State what is printed:
int a = 84, b = 1;
boolean boo = a != b;
System.out.println(boo);
State what is printed: int a = 84, b = 1; boolean boo = a != b; System.out.println(boo);
Signup and view all the answers
Determine the output of the following code segments. Write no output if there is no output.
int i = 2;
int j = 3;
if (i > j)
{ System.out.println ("You got it!");}
Determine the output of the following code segments. Write no output if there is no output. int i = 2; int j = 3; if (i > j) { System.out.println ("You got it!");}
Signup and view all the answers
How many different values can a boolean variable hold?
How many different values can a boolean variable hold?
Signup and view all the answers
The ________ method is where a program starts running.
The ________ method is where a program starts running.
Signup and view all the answers
Create the heading for class called Skeleton.
Create the heading for class called Skeleton.
Signup and view all the answers
Consider the following code:
System.out.print("Fire");
System.out.println(" Ants");
Which of the following is actually printed?
Consider the following code: System.out.print("Fire"); System.out.println(" Ants"); Which of the following is actually printed?
Signup and view all the answers
Which of the following is the most acceptable way of naming a variable?
Which of the following is the most acceptable way of naming a variable?
Signup and view all the answers
Which of the following is a keyword?
Which of the following is a keyword?
Signup and view all the answers
What data type would you use to store this number?
189.24
What data type would you use to store this number? 189.24
Signup and view all the answers
Study Notes
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
This quiz covers essential concepts of primitive data types in Java, including int
, double
, boolean
, and char
. Additionally, it discusses variable naming conventions and key components such as the main method header and comments. Test your understanding of these foundational concepts in Java programming.