Reviewer 1
Reviewer 1
Multiple Choice
Identify the choice that best completes the statement or answers the question
____ 1. You are creating a Java console application. You need to read a
birthdate entered by the user. How should you complete the code?
import (i)____________________;
(iv)_________________;
return birthdate;
}
}
a. (i) java.io.*;
(iii) stream.read();
(iv) stream.close();
b. (i) java.util.Scanner;
(iii) sc.next();
(iv) sc.close();
c. (i) java.io.*;
(iii) stream.mark(8);
(iv) stream.wait();
d. (i) java.util.Scanner;
(iii) sc.next();
(iv) sc.wait();
int x = 25;
int x=5;
int x=10;
int x = 100;
System.out.println(x);
System.out.println(app.x);
}
public JavaProgram1()
int x = 1;
System.out.println(x);
a. 1
100
25
b. 1
100
100
c. 1
10
100
d. 25
100
100
____ 3.
You are writing a Java program.
The program must meet the following requirements:
Truncate firstName to its first five characters
Set output to a string that contains the firstName and the number of characters
in firstName How should you complete the code? To answer, select the
appropriate code segments in the answer area.
String firstName=”Christopher”;
FirstName=FirstName._____________; (i)
System.out.println(output);
a. (i) substring(0,5)
(ii) %d
(iii) %s
(iv) length()
b. (i) subSequence(5,0)
(ii) %s
(iii) %f
(iv) length()
c. (i) substring(5)
(ii) %s
(iii) %f
(iv) chars()
d. (i) substring(0,5)
(ii) %s
(iii) %d
(iv) length()
___ 4.
You are writing a Java method that evaluates an arithmetic formula.
The method accepts an int value named number, raises the value to the second
power, and returns the negative value of the result.
How should you complete the code? To answer, drag the appropriate code
segment to the correct position. Each code segment may be used once, more
than once, or not at all. You may need to drag the split bar between panes or
scroll to view content.
a. (i) -
(ii) number
(iii) *
(iv) 2
b. (i) -
(ii) number
(iii) ^
(iv) 2
c. (i) -
(ii) number
(iii) *
(iv) number
d. (i) number
(ii) 2
(iii) *
(iv) number
____ 5. You are writing a Java method. The program must meet the following
requirements: Accept a String parameter firstName. Display a welcome
message that contains firstNam. Ensure that the first letter of the name
is capitalized, and the remaining letters are in lowercase How should
you complete the code? To answer, drag the appropriate code segment
to the correct position. Each code segment may be used once, more
than once, or not at all. You may need to drag the split bar between
panes or scroll to view content
(i) (ii)
(iii) (iv)
firstName.____________________(1).___________________();
a. (i) substring
(ii) toUpperCase
(iii) charAt
(iv) toLowerCase
b. (i) substring
(ii) toUpperCase
(iii) substring
(iv) toLowerCase
c. (i) charAt
(ii) toLowerCase
(iii) substring
(iv) toUpperCase
d. (i) charAt
(ii) toUpperCase
(iii) charAt
(iv) toLowerCase
____ 6. You are writing a Java console program. The program accepts
command line arguments. You need to ensure that the main method
parses and handles each command line argument. How should you
complete the code? To answer, select the appropriate code segments in
the answer area.
a. (i) ArrayList
(ii) args.length - 1
(iii) args[i]
b. (i) String
(ii) args.length
(iii) args[i]
c. (i) String[]
(ii) args[i]
(iii) args.charAt(i)
d. (i) String[]
(ii) args.length
(iii) args[i]
____ 7. You are writing a Java method. The method must meet the following
requirements: Accept a String array named entries Iterate through
entries Stop the iteration and return false if any element has more than
10 characters Otherwise, return trueHow should you complete the
code? To answer, select the appropriate code segments in the answer
area.
allValidEntries = false;
_________________(iii)
a. (i) do
(ii) :
(iii) break;
b. (i) for
(ii) instanceof
(iii) continue;
c. (i) for
(ii) :
(iii) break;
d. (i) while
(ii) ++
(iii) break;
____ 8. You are creating a method that processes invoices. The invoices are
contained in an ArrayList instance. After each invoice is processed, the method
must remove the invoice from the ArrayList instance. How should you complete
the code? To answer, select the appropriate code segments in the answer area.
a. (i) 0
(ii) size()
(iii) i=i+1
b. (i) 0
(ii) size()
(iii) )
c. (i) 1
(ii) size()+1
(iii) i=i+1)
d. (i) 0
(ii) size()-1
(iii) i=i+1)
____ 9. What is the value of (2+3) * 4 - 1
a. 13
b. 19
c. 26
d. 2
a. 90
b. 26
c. 15
d. 19
a. 1
b. 0
c. 5
d. 26
____ 12. What is the value of 5 / 2 - 4 % 2
a. 2
b. 1
c. 2.5
d. 15
____ 13. You are writing a method that accepts an int parameter named start
and display all numbers from start to zero in decrements of one.
System.out.println(i);
a. no change is needed
2 {
3 private int id = 3;
5 {
7 id=5;
8 showId();
9 }
10
13 System.out.println(id);
14 }
15 }
The code does not compile. What should you do to correct the code?
void preserve()
isPreserved = true;
{
Pickle pickle = new pickle();
pickle.isCreated = true;
pickle.preserve();
The code cannot compile due to error. How can we modify it?
b. Pickle.isCreated = true;
c. pickle.preserve;
You need to instantiate the db class and invoke the query method. Which is
correct?
b. DB db = DB(); query();
You need to create an array named numbers initialized with num1, num2, num3.
a. 3.142
b. 3.141
c. 3
d. 3.141593
a. 3.
b. 3
c. 3.1
d. 0
a. 3.141593
b. 0000000003.141593
c. Error
d. 03.141593
int b = 10;
System.out.println (c);
a. 15
b. 45
c. 60
d. 50
int b = 10;
System.out.println(d);
a. 13
b. 14
c. 15
d. 16
- stop the outer loop as soon as duplicate value has been detected and return
true
boolean isDup=false;
isDup= true;
if (isDup)
__________;
return isDup;
}
What should be the right code to complete this method?
a. false
b. true
c. break
d. continue
____ 25. Which of the following programs can be written with a switch
statement with up to three case statements?
Program 1
if (gpa == 4.0){
priority=1;
priority=2;
priority=3;
Program 2
discount=0.25;
} else { discount=0.0;
Program 3
if (grade == “A”) {
} else {
a. Program 1 only
b. Program 2 only
____ 26.
String str = "Java";
System.out.println(str+":"+buffer);
if (str.equals(buffer))
else
c. Compile time error as you cannot use equals for objects of different
classes
int price=0;
switch (model) {
break;
default : price=100;
break;
return price;
a. 50
b. 20
c. 25
d. 100
int price=0;
switch (model) {
break;
default : price=100;
break;
return price;
a. 50
b. 25
c. 20
d. 5
int price=0;
switch (model) {
break;
default : price=100;
break;
return price;
a. 5
b. 100
c. 20
d. 50
{
switch(digit)
case 'x': {
int j=0;
System.out.println(j);
}
default:
{
int j=100;
System.out.println(j);
}
int i=j;
System.out.println(i);
b. 100 will be printed 10 times and then there will be a runtime exception
c. The code will not compile because the variable i cannot be declared
twice within the main() method
d. None of these
boolean b = false;
boolean c = true;
System.out.println(b=c);
if (a == true)
if (b==true)
if (c==true)
d. None of these
if (s1==s2)
System.out.println("Same");
if (s1.equals(s2))
System.out.println("Equals");
a. Same
Equals
b. Equals
System.out.print(i);
System.out.print(i);
}
a. 0122
b. 0123
c. Compilation error
d. None of these
int a = 5;
a. Value is - 7
b. Value is - 5
c. Compilation error
d. None of these
____ 35. int Output = 10;
boolean b1 = false;
else
a. Not equal! 10
b. Not equal! 20
c. We are equal 10
d. We are equal 20
____ 36. Which of the following code will print current time?
a. System.out.print(new LocalTime().now());
b. System.out.print(new LocalTime());
c. System.out.print(LocalTime.now());
d. System.out.print(LocalTime.today());
Integer number=Integer.valueOf(“808.1”);
System.out.print(“name = “+wb.name);
System.out.print(“,pass=”+wb.pass);
a. name=,pass=
b. name=null,pass=false
c. name=null,pass=true
d. Compilation error
try
catch(ArrayIndexOutOfBoundsException e){
a. Compliation fails
b. Oops.. Identified Exception::
java.lang.ArrayIndexOutOfBoundsException: 11
c. Accessing Element : 0
____ 40. You work as a Java Programmer. You need to convert a numeric
String to primitive double value.
a. Double.valueOf(numberString);
b. double.parseDouble(numberString);
c. Double.parseDouble(numberString);
d. String.parseDouble(numberString);
class Logger
{
}
The logError method can be invoked by code in all classes in the same package
as the Logger class
Review the underlined text. If it makes the statement correct, select “No change
is needed”. If the statement is incorrect, select the answer choice that makes the
statement correct.
No change is needed
a.
only by the Logger class and classes in the same package that
c. inherit from it
number %= -3d;
number += 10f;
number *= -4;
System.out.println(number);
}
a. -44 c. 40.0
b. -40.0 d. 44.0
if (true) {
int num=1;
if (num > 0) {
num++;
int num = 1;
addOne(num);
System.out.println(num);
1
b.
2
c.
3
d.
____ 44. You are interviewing for a job as a Java developer. You need to
evaluate the following code.
03 String s3=s2;
04
05
(i) No
b. (ii) No
(iii) Yes
(iv) Yes
(i) No
c. (ii) Yes
(iii) No
(iv) Yes
(i) Yes
d. (ii) No
(iii) Yes
(iv) No
System.out.println(data1);
A
a.
65
b.
a
c.
An exception is thrown
d.
System.out.println(data2);
65.0
a.
65
b.
a
c.
An exception is thrown
d.
System.out.println(data3);
65.0
a.
-65.0
b.
A
c.
An exception is thrown
d.
System.out.println(data4);
65.0
a.
-65.0
b.
A
c.
An exception is thrown
d.
____ 49.
Traders hires you to write a Java program to manage account openings.
To open a new account, a user must meet one the following requirements:
be over 65 years old and have a minimum annual income of 10,000
be at least 21 and have an annual income greater than 25,000
How should you complete the code?
(age > 65 && income > 10000 || age > 21 && income > 25000)
a.
(age > 65 && income < 10000 || age < 21 && income > 25000)
b.
(age > 65 && income < 10000 || age > 21 && income > 25000)
c.
(age > 65 && income >= 10000 || age >= 21 && income > 25000)
d.
double dNum=2.667;
int iNum=0;
iNum=(int) dNum;
ANSWER:
1. B
2. A
3. D
4. C
5. B
6. D
7. C
8. A
9. B
10. B
11. A
12. A
13. A
14. D
15. C
16. D
17. C
18. B
19. A
20. B
21. D
22. C
23. D
24. C
25. C
26. A
27. A
28. D
29. B
30. D
31. D
32. B
33. C
34. D
35. A
36. C
37. D
38. B
39. B
40. C
41. C
42. B
43. A
44. A
45. A
46. B
47. B
48. D
49. D
50. C