1.
To make variable "dat" equal to 5
which of the following lines of Java code should be used:
Correct Answer
A. Int dat = 5;
Explanation
The correct answer is "int dat = 5;". This line of code declares a variable named "dat" of type integer and assigns it the value of 5. This will make the variable "dat" equal to 5. The other options are incorrect because they either assign a string value to the variable or attempt to print the value without declaring the variable first.
2.
To make a Java program print "Java", which of the following lines of Java code should be used:
Correct Answer
D. System.out.print("Java");
Explanation
The correct answer is System.out.print("Java"). This is because System.out.print is a method in Java that is used to print the specified text to the console. In this case, "Java" is the text that we want to print. The correct syntax for calling this method is to use parentheses () to enclose the text that we want to print. Therefore, the correct line of code to make a Java program print "Java" is System.out.print("Java").
3.
A program "class SavProg2" should be saved as:
Correct Answer
C. SavProg2.java
Explanation
The correct answer is "SavProg2.java" because in Java, the convention is to save a program file with the same name as the main class in the program. In this case, the main class is "SavProg2", so the file should be saved as "SavProg2.java".
4.
Which character usually ends up a Java program code?
Correct Answer
B. }
Explanation
The character "}" usually ends up a Java program code. This character is used to close a block of code, such as a class, method, or loop. It is important to have matching opening and closing braces to ensure the code is properly structured and executed. The other characters mentioned (@, &, #) do not typically signify the end of a Java program code.
5.
You cannot compile your Java program until you
Correct Answer
C. Save it
Explanation
To compile a Java program, it needs to be saved first. Saving the program ensures that the changes made to the code are stored in a file on the computer's storage. Once the program is saved, it can be compiled using a Java compiler, which will translate the code into a format that can be executed by the computer. Therefore, saving the Java program is a necessary step before compiling it.
6.
A Java class code contains the following
line:public class Diamondwhat is the actual name of the program (class)?
Correct Answer
C. Diamond
Explanation
The actual name of the program (class) is "Diamond". This is because in Java, the name of the class should match the name given after the "public class" statement. So, in this case, the name of the class is "Diamond".
7.
A computer keyboard is a:
Correct Answer
C. Input device
Explanation
A computer keyboard is classified as an input device because it allows users to input data and commands into a computer system. It consists of various keys that can be pressed to type letters, numbers, and special characters. The input from the keyboard is then processed by the computer's operating system or software applications. Keyboards are essential for tasks such as typing documents, sending emails, playing games, and navigating through computer interfaces.
8.
The line of Java code below has the last character missed.answer = number1 + 3The missed character is:
Correct Answer
D. ;
Explanation
The missing character in the given line of Java code is a semicolon (;). A semicolon is used to indicate the end of a statement in Java. In this code, the semicolon is missing after the expression "number1 + 3", which is a syntax error. Adding the semicolon at the end will correct the code.
9.
The text below is a fragment of a Java code. public class CalcNum {public static void main(String[] args) {double circ = 0This code should be saved as:
Correct Answer
B. CalcNum.java
Explanation
The correct answer is "CalcNum.java" because the code is defining a public class called "CalcNum" and the convention in Java is to save a public class in a file with the same name as the class, followed by the ".java" extension.
10.
An integer is:
Correct Answer
A. Any whole number (includes positive, negative, and zero)
Explanation
The correct answer is any whole number (includes positive, negative, and zero). This is because an integer is defined as a number that does not have a fractional or decimal part. It can be positive, negative, or zero, but it must be a whole number.