1/44
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Which of the following values can correctly be saved in a boolean?
true
In Java, what is the value of 3 + 7 * 4 + 2?
33
Which assignment is correct in Java?
double money = 12.0;
Which Java statement produces the following output?
w
xyz
System.out.println ("w\nxyz");
Assuming you have declared shoeSize to be a variable of type int, which of the following is a valid assignment statement in Java?
shoeSize = 9;
Which symbol represents the operator used to derive the remainder in division?
%
Which of the following arithmetic operations is calculated first in an arithmetic expression?
within the parentheses
Which of these identifiers does not follow standard Java naming conventions?
Which of these identifiers does not follow standard Java naming conventions?
What will the following code display in the output?
int num = 7, amt = 3;num *= 2;num++;amt = num;amt += num / 2;System.out.println("num is " + num + "; amt is " + amt);
num is 15; amt is 22
The concatenation operator (+) is used to:
Combine text and variable values.
Which class is imported when desiring user input?
Which class is imported when desiring user input?
Your source code includes this line: public class SayGoodbye
What must be the name of the source code file?
SayGoodbye.java
What does this error message indicate is the problem? java:15: error: ' ; ' expected
Line 15 in the source code is missing a semicolon (;).
Refer to the following code fragment:
double answer = 13 / 5;
System.out.println ("13 / 5 = " + answer);
The desired output is: 13 / 5 = 2.6
Which of the following replacements for the first line of code WILL NOT fix the problem?
double answer = (double) (13 / 5);
Given: int result = 13 - 3 * 7 / 4 % 3;
What value is stored in result?
11
What is the output for the following code?
System.out.println("LM");System.out.print(245);System.out.println("CB");System.out.print(789);
LM
245CB
789
After execution of the following line of code, what will be the value of num3 ?
double num3 = 15 / 3;
5.0
Which line of code has an error that will be caught by the compiler?
String str = Sea World;
Which of the following could be used to instantiate a new Studentobject called sam?
Student sam = new Student ( );
Given: String school = "Xavier Prep";
What is the return value of school.length( )?
11
Given: String school = "Xavier Prep";
What is the return value of school.indexOf ("e")?
Given: String school = "Xavier Prep";
What is the return value of school.indexOf ("e")?
String school = "Centennial";String mascot = "Coyotes";
What is the return value of school.substring (mascot.indexOf ("y"), mascot.length())?
ntenn
What is the output?
public static int calculate(int a, int b){int num1 = a - 4;int num2 = b - 8;int num3 = num1 * num2;return num3;}public static void main(String[] args){int amt = 7, num = 10;int x = calculate(amt, num);System.out.println(amt + " fries");System.out.println(x + " shakes");}
7 fries
6 shakes
Given the following method header: public static void costOrder (int a)
Which of the following statements about the costOrder method is accurate?
It has no return value.
Assume that a and b are integers. Given: ! (a <= b) && (a * b > 0)
The given boolean expression will always evaluate to true given that . . .
a > b and b > 0
Which of these conditions will evaluate to true if string1 is "Circle"and string2 is "circle"?
if (string1.equalsIgnoreCase(string2))
Which of the following are logical operators?
AND, NOT, OR
In the program below, what term or expression is missing?
if (x == y)
{
System.out.println ("x and y are equal.");
}
else if (x > y)
{
System.out.println ("x is greater than y.");
}
{
System.out.println ("x is less than y.");
}
else (x
Which of these expressions is a valid way to compare the characters in string1 and string2?
(string1.equals (string2))
What value of x would make this boolean expression evaluate to false?
(x < 10) && (x != 5)
Any value greater than or equal to 10
What is the output of the following code snippet?
double ticketPrice = 12.75;
if(ticketPrice > 15)
{
System.out.println("Too expensive!");
}
else if(ticketPrice > 10)
{
System.out.println("Typical");
}
else if(ticketPrice > 5)
{
System.out.println("Great deal!");
}
else
{
System.out.println("Must be a scam");
}
Typical
What is the output of this program?
int numTreeRings = 50;
System.out.println("How old is the tree?");
if(numTreeRings > 10)
{
System.out.println("Older than my pear tree");
}
if(numTreeRings > 40)
{
System.out.println("Older than my apple tree");
}
if(numTreeRings > 150)
{
System.out.println("Older than my pine tree");
}
How old is the tree?
Older than my pear tree
Older than my apple tree
What is the output of this code?
String firstName = "Karel";
String lastName = "The Dog";
if (firstName.length() > lastName.length())
{
System.out.println (firstName + " is longer than " + lastName);
}
else
{
System.out.println (lastName + " is longer than " + firstName);
}
The Dog is longer than Karel
Which for loop will properly print "hello" 10 times?
for (int i = 0; i < 10; i++)
{
System.out.println ("hello");
}
Given: String str = "cats";
Which of the following segments of code will produce the following output?
cats
for (int i = 0; i < str.length( ); i++)
{
System.out.println(str.substring (i, i + 1));
}
How many times will "Hello" be printed?
for(int x = 1; x <= 30; x++){for(int a = 1; a <= 7; a++){System.out.println("Hello");}}
210
Given that n and count are both of type int, which statement is true about the following code segments?
System.out.print("Enter an integer for n: ");
int n = scan.nextInt();
int count;
I. for (count = 1; count < n; count++)
System.out.println (count);
II. count = 1;
while (count <= n)
{
System.out.println (count);
count++
}
I and II produce the exact same output only when n = 0.
Which of the following logical statements is equivalent to the following: !(A && B)
Where A and B are boolean variables
!A || !B
Given: String school = "Xavier Prep";
What is the return value of school.substring(8)?
rep
A method is declared as: public static void showResults (double d, int i).
Which of the following is a correct method call?
showResults (12.2, 67);
Given the method header: public static int aMethod (double d)
What is the data type of the return value?
int
Given: String school = "Xavier Prep";
What is the return value of school.substring (1, 4)?
avi
What is printed as a result of executing the following statement?
System.out.println (7 + 8 + (7 +8) + "Hello" + 7 + 8 + (7 + 8) );
30Hello7815
A high school class places students in a course based on their average from a pervious course. Students that have an average 92 or above are placed in an honors level course. Students that have an average below 74 are placed in a remedial level course. All other students are placed in a regular level course. Which of the following statements correctly places the student based on their average?
I. if (average >= 92)
level = "honors";
if (average < 74)
level = "remedial";
else
level = regular;
II. if (average >= 92)
level = "honors";
else if (average >= 74)
level = "regular";
else
level = "remedial";
III. if (average >= 92)
level = "honors";
else if ( (average >= 74) && (average < 92) )
level = "regular";
else
level = "remedial";
II and III only
Consider the following code segment.
int amount = initValue;
if (amount >= 0)
if (amount <=10)
System.out.println ("**");
else
System.out.println("%%");
Which of the following declarations for variable initValue will result in the printing of %% ?
initValue = 5