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?
- String char double
- double boolean int (correct)
- char int String
- int double boolean
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?
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?
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?
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?
What is the data type of the following literal?
'A'
What is the data type of the following literal? 'A'
What data type holds true/false values?
What data type holds true/false values?
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?
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?
What are the two varieties of data in Java?
What are the two varieties of data in Java?
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?
A ______ is a note written to a human reader of a program.
A ______ is a note written to a human reader of a program.
Which of the following will result in an error?
Which of the following will result in an error?
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?
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.
(2 - 6) / 2 + 9
(2 - 6) / 2 + 9
Which of the following is legal?
Which of the following is legal?
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);
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
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.
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);
What is another way to write p = p - 1;?
What is another way to write p = p - 1;?
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?
State what is printed.
System.out.println((double)(90/9));
State what is printed. System.out.println((double)(90/9));
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.
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?
What is the purpose of wrapper classes?
What is the purpose of wrapper classes?
Write a Java formula using the Math class for:
Distance = |val1 - val2|
Write a Java formula using the Math class for: Distance = |val1 - val2|
Evaluate:
Math.ceil(115.8)
Evaluate: Math.ceil(115.8)
Evaluate:
Math.abs(2 + -4)
Evaluate: Math.abs(2 + -4)
Evaluate:
Math.sqrt(16) * Math.max(Math.abs(-5), Math.abs(-3))
Evaluate: Math.sqrt(16) * Math.max(Math.abs(-5), Math.abs(-3))
The classes that convert primitives to objects are called _____ classes
The classes that convert primitives to objects are called _____ classes
Evaluate:
Math.min( 8, 3 + 2 )
Evaluate: Math.min( 8, 3 + 2 )
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.
Evaluate:
Math.sqrt(76 + 45)
Evaluate: Math.sqrt(76 + 45)
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?
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();
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);
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?
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);
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?
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?
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);
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?
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?
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";
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' ?
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";
What is returned by a method of type void?
What is returned by a method of type void?
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.
What is the relationship between an object, method, and a class.
What is the relationship between an object, method, and a class.
Which of the following is equivalent to
!(a && (c < d))
Which of the following is equivalent to !(a && (c < d))
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?
The boolean expression
!(A || B)
evaluates to
The boolean expression !(A || B) evaluates to
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);
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?
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));
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++);
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;
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?
The boolean expression
(A || B) && (!A || !B)
evaluates to
The boolean expression (A || B) && (!A || !B) evaluates to
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?
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?
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?
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?
Show the basic skeleton of an if - else structure.
Show the basic skeleton of an if - else structure.
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!");}
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.
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!");}
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);
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!");}
How many different values can a boolean variable hold?
How many different values can a boolean variable hold?
The ________ method is where a program starts running.
The ________ method is where a program starts running.
Create the heading for class called Skeleton.
Create the heading for class called Skeleton.
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?
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?
Which of the following is a keyword?
Which of the following is a keyword?
What data type would you use to store this number?
189.24
What data type would you use to store this number? 189.24
Flashcards
String
String
A sequence of characters enclosed in double quotes, representing text.
Camel Case
Camel Case
A naming convention where each word in a variable name starts with a capital letter, except the first word, which is lowercase.
Primitive data types
Primitive data types
Basic building blocks of data in Java, representing fundamental values: double, int, boolean.
double
double
Signup and view all the flashcards
boolean
boolean
Signup and view all the flashcards
int
int
Signup and view all the flashcards
char
char
Signup and view all the flashcards
Data Types in Java
Data Types in Java
Signup and view all the flashcards
Main Method
Main Method
Signup and view all the flashcards
Comments
Comments
Signup and view all the flashcards
Assignment statement
Assignment statement
Signup and view all the flashcards
Expression evaluation
Expression evaluation
Signup and view all the flashcards
Wrapper Classes
Wrapper Classes
Signup and view all the flashcards
Math.abs()
Math.abs()
Signup and view all the flashcards
Math.sqrt()
Math.sqrt()
Signup and view all the flashcards
Math.random()
Math.random()
Signup and view all the flashcards
String.length()
String.length()
Signup and view all the flashcards
String.substring()
String.substring()
Signup and view all the flashcards
String.indexOf()
String.indexOf()
Signup and view all the flashcards
String.compareTo()
String.compareTo()
Signup and view all the flashcards
Object
Object
Signup and view all the flashcards
Method
Method
Signup and view all the flashcards
Class
Class
Signup and view all the flashcards
Boolean Expression
Boolean Expression
Signup and view all the flashcards
Logical Operators
Logical Operators
Signup and view all the flashcards
If-else Statement
If-else Statement
Signup and view all the flashcards
Keyword
Keyword
Signup and view all the flashcards
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.