Java Section 4 Ilearning
Java Section 4 Ilearning
Java Section 4 Ilearning
Section 4 Quiz
(Answer all questions in this section)
2. The String methods equals and compareTo perform similar functions and differ in
their return type. True or false? Mark for Review
(1) Points
True (*)
False
6. Which of the two diagrams below illustrate the general form of a Java program?
Mark for Review.
(1) Points
Example A
Example B (*)
7. When importing another package into a class you must import only the package
classes that will be called and not the entire package. True or false? Mark for Review
(1) Points
True
False (*)
8. What two values can a boolean variable have? Mark for Review
(1) Points
Relational and logic operators
Arithmetic and logic operators
True and false (*)
Numbers and characters
Integers and floating point types
9. Which line of Java code assigns the value of 5 raised to the power of 8 to
a? Mark for Review
(1) Points
int a=Math.pow(5,8);
double a=Math.pow(5,8); (*)
double a=15^8;
int a=Math.pow(8,5);
double a=pow(8,5);
int j=6,k=8,m=2,result;
result=j-k%3*m;
System.out.println(result); Mark for Review
(1) Points
-42
2 (*)
6
0
12. Write a declaration statement that will hold a number like 2.541. Mark for
Review
(1) Points
float number; (*)
boolean number;
char number;
int number;
13. For every opening curly brace { there must be a closing curly brace} or the
program will not compile without error. True or False? Mark for Review
(1) Points
True (*)
False
14. You can return to the Eclipse Welcome Page by choosing Welcome from what
menu? Mark for Review
(1) Points
Close
Edit
File
Help (*)
15. Tabs are used when more than one file is open in the edit area. True or
False? Mark for Review
(1) Points
True (*)
False
You are writing a class and are using a global variable. Inside a method you declare a
local variable with the same name as the global variable.
This programming style is poor because inside the method the global variable will have
precedence over the local variable with the same name.
2. Which of the following statements correctly assigns "3 times 10 to the 4th power"
to the variable number? Mark for Review
(1) Points
double number=3(e4);
double number=3*10e4;
double number=3*10^4;
double number=3e4; (*)
3. Which line of code does not assign 3.5 to the variable x? Mark for Review
(1) Points
3.5=x; (*)
x=7.0/2.0;
double x=3.5
x=3.5;
4. A local variable has precedence over a global variable in a Java method. True or
false? Mark for Review
(1) Points
True (*)
False
6. For every opening curly brace { there must be a closing curly brace} or the
program will not compile without error. True or False? Mark for Review
(1) Points
True (*)
False
7. The ______________ is the location into which you will store and save your files.
Mark for Review
(1) Points
Perspective
Workspace (*)
Editor
None of the above
8. What symbols are required for a compiler to ignore a comment? Mark for
Review
(1) Points
/*/
/*
*/
// (*)
9. The following program prints "Equal". True or false?
10. Suppose that s1 and s2 are two strings. Which of the statements or expressions are
valid? Mark for Review
(1) Points
(Choose all correct answers)
String s3 = s1 + s2; (*)
String s3 = s1 - s2;
s1.compareTo(s2); (*)
int m = s1.length(); (*)
s1 <= s2
11. Declaring and instantiating a String is much like any other type of variable.
However, once instantiated, they are final and cannot be changed. True or false? Mark
for Review
(1) Points
True (*)
False
15. When importing another package into a class you must import the entire package
as well as the package classes that will be called. True or False? Mark for Review
(1) Points
True
False (*)
1. Match each of the following literals ('x', 10, 10.2, 100L, "hello") with its
respective data type. Mark for Review
(1) Points
char, boolean, float, long, String
char, double, int, long, String
char, int, long, float, String
boolean, byte, int, long, Short
char, int, double, long, String (*)
2. Which line of Java code will assign the value of the square root of 11 to a variable
named a? Mark for Review
(1) Points
int a=Math.sqrt(11);
double a=11^(1/2);
double a=Math.sqrt*11;
double a=Math.sqrt(11); (*)
double a=sqrt(11);
You are writing a class and are using a global variable. Inside a method you declare a
local variable with the same name as the global variable.
This programming style is poor because inside the method the global variable will have
precedence over the local variable with the same name.
5. Select the declaration and initialization statement that will hold the letter
J. Mark for Review
(1) Points
String letter='J';
char letter='J'; (*)
int letter='J';
float letter='J';
6. For every opening curly brace { there does not need to be a closing curly brace}
for the program to compile without error. True or False? Mark for Review
(1) Points
True
False (*)
9. The == operator can be used to compare two String objects. The result is always
true if the two strings are identical. True or false? Mark for Review
(1) Points
True
False (*)
13. Which of the two diagrams below illustrate the general form of a Java program?
15. Which of the following defines a driver class? Mark for Review
(1) Points
Contains a main method and other static methods. (*)
Contains classes that define objects.
Contains a main method, a package, static methods, and classes that define
objects.
None of the above.
1. In Eclipse, when you run a Java Application, the results are displayed in a new
window. True or False? Mark for Review
(1) Points
True
False (*)
2. Multiple windows are used when more than one file is open in the edit area. True
or False? Mark for Review
(1) Points
True
False (*)
3. What is the purpose of the Eclipse Editor Area and Views? Mark for Review
(1) Points
(Choose all correct answers)
To choose the file system location to delete a file.
To modify elements. (*)
To navigate a hierarchy of information. (*)
String s;
10. Given the code below, which of the following would equate to true?
String s1 = "yes";
String s2 = "yes";
String s3 = new String(s1);
Mark for Review
(1) Points
11. Which line of Java code will assign the value of the square root of 11 to a variable
named a? Mark for Review
(1) Points
double a=11^(1/2);
double a=sqrt(11);
double a=Math.sqrt(11); (*)
double a=Math.sqrt*11;
int a=Math.sqrt(11);
12. Which line of Java code assigns the value of 5 raised to the power of 8 to
a? Mark for Review
(1) Points
int a=Math.pow(5,8);
int a=Math.pow(8,5);
double a=pow(8,5);
double a=15^8;
double a=Math.pow(5,8); (*)
13. Which line of Java code properly calculates the area of a triangle using
A=1/2(b)(h) where b and h are Java primitive integers? Mark for Review
(1) Points
double A=1/2bh;
double A=(double)1/(double)2*b*h; (*)
double A=(double)(1/2)*b*h;
double A=1/2*b*h;
int j=7,k=5,m=8,result;
result=j/m*k;
System.out.println(result); Mark for Review
(1) Points
0.175
280
4.375
0 (*)
15. Which of the following is not a legal name for a variable? Mark for Review
(1) Points
theLastValueButONe
zero
year2000
2bad (*)
1. What is the purpose of the Eclipse Editor Area and Views? Mark for Review
(1) Points
(Choose all correct answers)
To modify elements. (*)
To choose the file system location to delete a file.
To navigate a hierarchy of information. (*)
3. A workspace can have one or more stored projects. True or false? Mark for
Review
(1) Points
True (*)
False
4. Which of the two diagrams below illustrate the general form of a Java program?
7. Which of the two diagrams below illustrate the general form of a Java program?
Mark for Review
(1) Points
Example A
Example B (*)
9. Which of the following is not correct Java code? Mark for Review
(1) Points
double x=Math.pow; (*)
double x=Math.sqrt(16);
double x=Math.pow(3,4)*5.0;
double x=Math.PI*5.0;
int j=7,k=5,m=8,result;
result=j/m*k;
System.out.println(result); Mark for Review
(1) Points
0.175
280
4.375
0 (*)
int j=6,k=8,m=2,result;
result=j-k%3*m;
System.out.println(result); Mark for Review
(1) Points
-42
0
2 (*)
6
12. What two values can a boolean variable have? Mark for Review
(1) Points
Arithmetic and logic operators
Integers and floating point types
Numbers and characters
Relational and logic operators
True and false (*)
14. Declaring and instantiating a String is much like any other type of variable.
However, once instantiated, they are final and cannot be changed. True or false? Mark
for Review
(1) Points
True (*)
False
15. Consider the following code snippet.
What is printed?
Mark for Review
(1) Points
AtlanticPacificIndianArcticSouthern
Code does not compile
87658
55555
ArrayIndexOutofBoundsException is thrown (*)