10 QUESTIONS PLEASE ANSWER fast Analyze the following code i
10 QUESTIONS, PLEASE ANSWER fast.
Analyze the following code.
int x = 0;
if (x > 0);
{
System.out.println(\"x\");
}
Select one:
a. Nothing is printed because x > 0 is false.
b. The symbol x is always printed.
c. The symbol x is always printed twice.
d. The value of variable x is always printed.
How many times will the following code print \"Welcome to Java\"?
int count = 0;
do {
System.out.println(\"Welcome to Java\");
count++;
} while (count < 10);
Select one:
a. 0
b. 9
c. 11
d. 10
Given the following method:
public static int m(int x) {
x++;
return 2 * x;
}
What is the output of the following code?
int x = 1;
System.out.println(x + \" \" + m(x));
Select one:
a. 1 4
b. 1 2
c. 2 2
d. 2 4
The expression (int)(76.0252175 * 100) / 100 evaluates to _________.
Select one:
a. 76.02
b. 76
c. 76.0252175
d. 76.03
Which of the following is a constant, according to Java naming conventions?
Select one:
a. Test
b. ReadInt
c. read
d. MAX_VALUE
What is y after the following switch statement is executed?
x = 3;
switch (x + 3) {
case 6: y = 0;
case 7: y = 1;
default: y += 1;
}
Select one:
a. 4
b. 2
c. 3
d. 1
What is i after the following for loop is finished?
int y = 0;
for (int i = 0; i<10; ++i) {
y += i;
}
Select one:
a. 9
b. 11
c. undefined
d. 10
Which of the following should be declared as a void method?
Select one:
a. Write a method that converts an uppercase letter to lowercase.
b. Write a method that checks whether current second is an integer from 1 to 60.
c. Write a method that prints integers from 1 to 100.
d. Write a method that returns a random integer from 1 to 100.
Which of the following assignment statements is correct to assign character 5 to c?
Select one:
a. char c = \'5\';
b. char c = \"344\";
c. char c = \"5\";
d. char c = 5;
What is the printout of the following switch statement?
char ch = \'a\';
switch (ch) {
case \'a\':
case \'A\':
System.out.print(ch); break;
case \'b\':
case \'B\':
System.out.print(ch); break;
case \'c\':
case \'C\':
System.out.print(ch); break;
case \'d\':
case \'D\':
System.out.print(ch);
}
Select one:
a. aa
b. abc
c. ab
d. a
Solution
-----------------------------A—N—S—W—E--R-----------------------------------------------
Analyze the following code.
int x = 0;
if (x > 0);
{
System.out.println(\"x\");
}
Select one:
a. Nothing is printed because x > 0 is false.
b. The symbol x is always printed.
c. The symbol x is always printed twice.
d. The value of variable x is always printed.
Answer: - b
Description: - Here there is semicolon in line no 2 so line no 4 will always executed.
---------------------------------------------------------------------------------------------
How many times will the following code print \"Welcome to Java\"?
int count = 0;
do {
System.out.println(\"Welcome to Java\");
count++;
} while (count < 10);
Select one:
a. 0
b. 9
c. 11
d. 10
Answer: - d
Description: - The following code print \"Welcome to Java\" 10 times. Whenever count will 11 then count< 10 condition became false and it will come out from do – while Loop.
---------------------------------------------------------------------------------------------
Given the following method:
public static int m(int x) {
x++;
return 2 * x;
}
What is the output of the following code?
int x = 1;
System.out.println(x + \" \" + m(x));
Select one:
a. 1 4
b. 1 2
c. 2 2
d. 2 4
Answer: - a
Description: - Here initial x value is 1 and m(x) function return value 4.
So output is 1 4
---------------------------------------------------------------------------------------------
The expression (int)(76.0252175 * 100) / 100 evaluates to _________.
Select one:
a. 76.02
b. 76
c. 76.0252175
d. 76.03
Answer: - b
Description: - Integer / integer always return integer value. So here correct answer is 76
---------------------------------------------------------------------------------------------
Which of the following is a constant, according to Java naming conventions?
Select one:
a. Test
b. ReadInt
c. read
d. MAX_VALUE
Answer: - d
Description: - MAX_VALUE is constant, according to Java naming conventions.
---------------------------------------------------------------------------------------------
What is y after the following switch statement is executed?
x = 3;
switch (x + 3) {
case 6: y = 0;
case 7: y = 1;
default: y += 1;
}
Select one:
a. 4
b. 2
c. 3
d. 1
Answer: - b
Description: - It start from case 6, so y=0, there is no break statement so it executes next case 7, so y=1 again there is no break statement so it executes next case that is default and y =y+1, so y =2
Here logic is whenever a break statement is reached, the switch terminates, and the flow of control jumps to the next line following the switch statement.
---------------------------------------------------------------------------------------------
What is i after the following for loop is finished?
int y = 0;
for (int i = 0; i<10; ++i) {
y += i;
}
Select one:
a. 9
b. 11
c. undefined
d. 10
Answer: - d
Description: - when the following for loop is finished then i=10.
---------------------------------------------------------------------------------------------
Which of the following should be declared as a void method?
Select one:
a. Write a method that converts an uppercase letter to lowercase.
b. Write a method that checks whether current second is an integer from 1 to 60.
c. Write a method that prints integers from 1 to 100.
d. Write a method that returns a random integer from 1 to 100.
Answer: - C
Description: - Here option c is correct, because have to multiple value, there is no single return value.
---------------------------------------------------------------------------------------------
Which of the following assignment statements is correct to assign character 5 to c?
Select one:
a. char c = \'5\';
b. char c = \"344\";
c. char c = \"5\";
d. char c = 5;
Answer: - a
Description:- char c = \'5\' is the assignment statements is correct to assign character 5 to c
---------------------------------------------------------------------------------------------
What is the printout of the following switch statement?
char ch = \'a\';
switch (ch) {
case \'a\':
case \'A\':
System.out.print(ch); break;
case \'b\':
case \'B\':
System.out.print(ch); break;
case \'c\':
case \'C\':
System.out.print(ch); break;
case \'d\':
case \'D\':
System.out.print(ch);
}
Select one:
a. aa
b. abc
c. ab
d. a
Answer: - d
Description: - Here initially ch is ‘a’ so case ‘a’(line no 3) will execute but there is no break statement so it continue execute next case ‘A’ and output is ‘a’, now there is break() statement so it terminate from switch.
---------------------------------------------------------------------------------------------
If you have any query, please feel free to ask
Thanks a lot




