Answers.
Which of the following is a value that is written into the code of a program? - Answer
Literal
A Java program must have at least one of the following - Answer a class definition
Which of the following is a named storage location in the computer's memory? -
Answer a variable
Which of the following is not a valid Java comment? - Answer */ Comment two/*
To compile a program named First you would use which of the following commands?
- Answer javac First.java
A Java source file must be saved with the extension - Answer .java
Character literals are enclosed in ________; string literals are enclosed in ________.
- Answer single quotes, double quotes
Variable are classified according to their - Answer data types
What is the result of the following expression:
17 % 3 * 2 - 12 + 15 - Answer 7
What is the result of the following expression:
10 + 5 * 3 - 20 - Answer 5
What output will be displayed as a result of executing the following code:
int x = 5, y = 20;
x += 32;
y /= 4;
System.out.println("x =" + x + ", y =" + y); - Answer x = 37, y = 5
What would be displayed as a result of executing the following code:
int x = 578;
System.out.print("There are" + x + 5 "\n" + "hens in the hen house."; - Answer There
are 5785
hens in the hen house.
Which of the following statements correctly creates a Scanner object for keyboard
input? - Answer Scanner keyboard = new Scanner(System.in);
If the following Java statements are executed, what will be displayed?
, System.out.println("The top three winners are\n");
System.out.print("Jody, the Giant\n");
System.out.print("Buffy, the Barbarian");
System.out.println("Adelle, the Alligator"); - Answer The top three winners are
Jody, the Giant
Buffy, the BarbarianAdelle, the Alligator
When the + operator is used with strings, it is known as the: - Answer string
concatenation operator
Which of the following cannot be used as identifiers in Java? - Answer key words
If x has been declared an int, which of the following statements is invalid? - Answer x
= 1,000;
To display the output on the next line, you can use the println method or use the
_________ escape sequence in the print method. - Answer \n
Every Java application must have - Answer a method named main
In an if-else statement, if the boolean expression is false then______ - Answer the
statement or block following the else is executed
The switch statement is a _______ - Answer multiple alternative decision structure
If str1 and str2 are both String objects, which of the following expressions will
correctly determine whether or not they are equal? - Answer str1.equals(str2)
A block of code is enclosed in a set of _______ - Answer braces, { }
What will be the value of x after the following statements are executed:
int x = 75;
int y = 60
if (x>y)
x = x - y; - Answer 15
What will be displayed after the following statements are executed:
int y = 10;
if (y == 10)
{
int x = 30
x += y;
System.out.println(x);
} - Answer 40
What will be the value of the pay after the following statements are executed: