Computer Programming 2 Midterm Lab Exam
Computer Programming 2 Midterm Lab Exam
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What will be the output if you execute this code?
do{System.out.println("Hello World!");}while(true);
Select one:
a.
print "Hello World"
b.
print "Hello World" infinitely
c.
Do nothing
d.
None of these
e.
The code will not run because of syntax error
Feedback
Your answer is correct.
Question 2
Correct
Mark 2.00 out of 2.00
Flag question
Question text
Which of the following is a valid statement to accept int input? Let us assume
that we have declared scan as Scanner.
Select one:
a.
int num = scan.getInt();
b.
short num = scan.nextShort();
c.
None of these
d.
int num = scan.nextLong();
e.
short num = scan.nextInt();
Question 3
Correct
Mark 2.00 out of 2.00
Flag question
Question text
What will be the output if you execute this code?
do{System.out.println("Hello World!");}while(false);
Select one:
a.
The code will not run because of syntax error
b.
Do nothing
c.
None of these
d.
print "Hello World"
e.
print "Hello World" infinitely
Feedback
Your answer is correct.
Question 4
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which is not a decision control structure?
Select one:
a.
switch
b.
None of these
c.
if else-if else
d.
if else
e.
if
Question 5
Correct
Mark 2.00 out of 2.00
Flag question
Question text
What is the output of the code snippet below:
int[] intArray = new int[10];
for(int x = 0; x<intArray.length; x++){System.out.print(intArray[x]);}
Select one:
a.
None of the choices
b.
1235678910
c.
012356789
d.
The given code is not valid
e.
0000000000
Feedback
Your answer is correct.
Question 6
Correct
Mark 2.00 out of 2.00
Flag question
Question text
What is the output of the code snippet below:
void main(){test(“11”);test(“1”);}
void test(String x){System.out.print(x + x);}
Select one:
a.
None of the choices
b.
6
c.
111111
111
d.
222
Feedback
Your answer is correct.
Question 7
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of the following is a valid method name:
Select one:
a.
compute
b.
int
c.
None of these
d.
final
e.
compute grade
Feedback
Your answer is correct.
Question 8
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What is the return value of this method: int test(){return 1;} ?
Select one:
a.
test
b.
All of the choices
c.
int
d.
1
e.
return 1
Feedback
Your answer is correct.
Question 9
Correct
Mark 1.00 out of 1.00
Flag question
Question text
what will be the output if you execute this code?
int x=1;
switch(x){
case 1:
System.out.print(“1”);
case 2:
System.out.print(“1”);
case 3:
System.out.print(“1”);
default:
System.out.print(“1”);
}
Select one:
a.
display 1
b.
display nothing
c.
display 1234
d.
display 1111
e.
None of these
Feedback
Your answer is correct.
Question 10
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of the following is a valid nextInt() return value?
Select one:
a.
None of these
b.
3.1416
c.
floating-point literal
d.
1010
e.
long value
Question 11
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which statement will check if x is less than y?
Select one:
a.
if (x<y);
b.
if (x>y)?:
c.
None of these
d.
if (x<>y)
e.
if (x>y)
Feedback
Your answer is correct.
Question 12
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What is the index number of the last element of an array with 30 elements?
Select one:
a.
30
b.
0
c.
None of these
d.
31
e.
29
Question 13
Correct
Mark 2.00 out of 2.00
Flag question
Question text
Which of the following is a valid nextByte() return value?
Select one:
a.
None of these
b.
short value
c.
128
d.
3
e.
int value
Question 14
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What is the output of the code snippet below:
void main(){
test(1.0);
test(1);}
void test(double x){
System.out.print(x); }
void test(int x){
System.out.print(x);}
Select one:
a.
11
b.
1.01.0
c.
None of the choices
d.
1.01
e.
1.0
Feedback
Your answer is correct.
Question 15
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of the following has the correct form for an if statement?
Select one:
a.
None of these
b.
boolean_expression
c.
if boolean_expression
d.
if boolean_expression
e.
if (boolean_expression)
Question 16
Correct
Mark 2.00 out of 2.00
Flag question
Question text
Which of the following is a valid statement to accept String input?
Select one:
a.
String num = scan.nextText();
b.
String str = scan.nextString();
c.
string str = scan.nextShort();
d.
String str = JOptionPane.showInputDialog("");
e.
None of these
Question 17
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What is the return value of this method: public void sum(){int x=1;} ?
Select one:
a.
1
b.
sum
c.
x
d.
None of the choices
e.
void
Feedback
Your answer is correct.
Question 18
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What is the output of the code snippet below: void main(){test();test();} void
test(){System.out.print(“1”);}
Select one:
a.
2
b.
None of the choices
c.
3
d.
11
e.
1
Feedback
Your answer is correct.
Question 19
Correct
Mark 2.00 out of 2.00
Flag question
Question text
Which of the following correctly accesses the sixth element stored in an array of
10 elements?
Select one:
a.
intArray[7];
b.
intArray[10];
c.
intArray[6];
d.
None of these
e.
stringArray[5];
Question 20
Correct
Mark 2.00 out of 2.00
Flag question
Question text
Which of the following is a valid nexDouble() return value?
Select one:
a.
double value
b.
floating-point literal
c.
3.1416
d.
12.0
e.
All of these
Question 21
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What will happen if you use JOptionPane.showMessageDialog statement in your
program?
Select one:
a.
The program will display an input dialog box that allows the user to input text
and returns the correct type value.
b.
The program will display an input dialog box that allows the user to input text
and returns String value.
c.
The program will display message dialog box returns String value.
d.
None of these
e.
The program will display message dialog box.
Question 22
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What is the name of this method: int test(){return 1;} ?
Select one:
a.
int
b.
7
c.
None of the choices
d.
test
e.
6
Feedback
Your answer is correct.
Question 23
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What will be the value of x after executing this code
for(int x=0; x<=10; x++) {} is run?
Select one:
a.
11
b.
0
c.
10
d.
1
e.
None of these
Feedback
Your answer is correct.
Question 24
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of the following declares an array of int named intArray?
Select one:
a.
int[] intArray;
b.
int[][] intArray;
c.
int intArray[];
d.
All of these
e.
int intArray[][];
Question 25
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of the following does not return numeric value?
Select one:
a.
None of these
b.
nextDouble()
c.
nextInt()
d.
nextShort()
e.
nextLong()
Question 26
Correct
Mark 1.00 out of 1.00
Flag question
Question text
From the array int[] intArray = { 1, 2, 3, 5, 6, 7 };, what is the value of
intArray[3]?
Select one:
a.
None of the choices
b.
4
c.
5
d.
6
e.
7
Feedback
Your answer is correct.
Question 27
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which is not a repetition control structure?
Select one:
a.
while
b.
None of these
c.
do while
d.
switch
e.
for
Question 28
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of the following correctly accesses the sixth element stored in an array of
10 elements?
Select one:
a.
intArray[6];
b.
stringArray[5];
c.
intArray[10];
d.
intArray[7];
e.
None of these
Question 29
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What is the length of the array: int[] intArray = { 1, 2, 3, 5, 6, 7 };
Select one:
a.
None of the choices
b.
7
c.
4
d.
5
e.
6
Feedback
Your answer is correct.
Question 30
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What will happen if you use JOptionPane. showInputDialog statement in your
program?
Select one:
a.
The program will display an input dialog box that allows the user to input text
and returns String value.
b.
The program will display message dialog box returns String value.
c.
The program will display an input dialog box that allows the user to input text
and returns the correct type value.
d.
None of these
e.
The program will display message dialog box.
Question 31
Correct
Mark 2.00 out of 2.00
Flag question
Question text
Which statement will check if x is equal to y?
Select one:
a.
if (y>y)
b.
None of these
c.
if (x>y)
d.
if (x<>y)
e.
if (x!<y)
Feedback
Your answer is correct.
Question 32
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What type of value does the nextLine() returns?
Select one:
a.
None of these
b.
Line
c.
String
d.
long
e.
double
Question 33
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What is the return type of this method: int test(){return 1;} ?
Select one:
a.
None of these
b.
1
c.
test()
d.
int
e.
void
Feedback
Your answer is correct.
Question 34
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of the following shows Overloading method?
Select one:
a.
void test(){} void test(){}
b.
void test(int x){} void test(double x){}
c.
All of these
d.
void test(int x){} void test(int y){}
Feedback
Your answer is correct.
Question 35
Correct
Mark 2.00 out of 2.00
Flag question
Question text
What will be the value of x after you execute this statement
int z=0; for(int x=0; x<10; x++) for(int y=0; y<x; y++) z*=(x*y);
Select one:
a.
None of these
b.
128
c.
236
d.
512
e.
1
Feedback
Your answer is correct.
Question 36
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of the following is a valid multidimensional array?
Select one:
a.
All of these
b.
int[][] intArray;
c.
int[][][][] intArray;
d.
int[][][] intArray;
e.
int intArray[][][];
Question 37
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What is the maximum index of the array: int[] intArray = { 1, 2, 3, 5, 6, 7 };
Select one:
a.
5
b.
None of the choices
c.
4
d.
6
e.
7
Feedback
Your answer is correct.
Question 38
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of the following shows a valid Overloading method?
Select one:
a.
void test(int x){} void test(int y){}
b.
void test(char x, int y){} void test(int x, char y){}
c.
None of these
d.
void test(){} void test(){}
Feedback
Your answer is correct.
Question 39
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What is the output of the code snippet below:
int[] intArray = { 1, 2, 3, 5, 6, 7 };
for(int x = intArray.length-1; x>=0; x--){System.out.print(intArray[x]);}
Select one:
a.
The given code is not valid
b.
12356
c.
None of these
d.
123567
e.
765321
Feedback
Your answer is correct.
Question 40
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of the following method reads input from the user and return String
value?
Select one:
a.
nextLine()
b.
All of these
c.
nextText()
d.
nextValue()
e.
nextString()