13 questions, please answer fast. hat is y after the following switch statement?
ID: 3924161 • Letter: 1
Question
13 questions, please answer fast.
hat is y after the following switch statement? int x = 0; int y = 0; switch (x + 1) { case 0: y = 0; case 1: y = 1; default: y = -1 }
Select one:
a. -1
b. 1
c. 2
d. 0
The keyword _______ must be used to declare a constant.
Select one:
a. const
b. static
c. final
d. double
What is the output of the following fragment?
int i = 1;
int j = 1;
while (i < 5) {
i++;
j = j * 2;
}
System.out.println(j);
Select one:
a. 4
b. 32
c. 16
d. 8
Analyze the following code.
int x = 1;
while (0 < x) && (x < 100)
System.out.println(x++);
Select one:
a. The loop runs forever.
b. The code does not compile because (0 < x) && (x < 100) is not enclosed in a pair of parentheses.
c. The numbers 1 to 99 are displayed.
d. The code does not compile because the loop body is not in the braces.
Next
Analyze the following code:
Code 1:
boolean even;
if (number % 2 == 0)
even = true;
else
even = false;
Code 2:
boolean even = (number % 2 == 0);
Select one:
a. Both Code 1 and Code 2 are correct, but Code 2 is better.
b. Code 2 has syntax errors.
c. Code 1 has syntax errors.
d. Both Code 1 and Code 2 have syntax errors.
The signature of a method consists of ____________.
Select one:
a. method name and parameter list
b. parameter list
c. method name
d. method name, parameter list and internal program
When you invoke a method with a parameter, the value of the argument is passed to the parameter. This is referred to as _________.
Select one:
a. pass by name
b. pass by value
c. method invocation
d. pass by reference
iven two Strings s1 = "Welcome to Java" and s2 = "Programming is fun", which of the following is true?
Select one:
a. s1.equals(s2)
b. s2.equals(s1)
c. !s1.contains(s2)
d. s2.contains(s1)
Each time a method is invoked, the system stores parameters and local variables in an area of memory, known as _______, which stores elements in last-in first-out fashion.
Select one:
a. a heap
b. an array
c. storage area
d. a stack
Analyze the following code.
int count = 0;
while (count < 100) {
// Point A
System.out.println("Welcome to Java!");
count++;
// Point B
}
//Point C
Select one:
a. count < 100 is always true at Point C
b. count < 100 is always false at Point C
c. count < 100 is always false at Point A
d. count < 100 is always true at Point B
Assume x is 0. What is the output of the following statement?
if (x > 0)
System.out.print("x is greater than 0");
else if (x < 0)
System.out.print("x is less than 0");
else
System.out.print("x equals 0");
Select one:
a. None
b. x is less than 0
c. x equals 0
d. x is greater than 0
Which of the following method returns the sine of 90 degree?
Select one:
a. Math.sin(Math.toRadians(90))
b. Math.sine(90)
c. Math.sin(90)
d. Math.sin(PI)
"abcdefgh".subString(1, 3) returns ________.
Select one:
a. abc
b. bc
c. bcd
d. cde
Explanation / Answer
1) y = -1 since there is not break statement after case 1, the default case will also be visited. Thus y will equal -1.
2) "const" is the keyword used to create a constant. Example, const int a=10, will handle 'a' as constant 10. The value of 'a' cannot be modified.
3) j will be equal to 16. the while loop will execute for 4 times. Thus, j=j*2 will execute for 4 times with initial value of j=1.
iteration 1: j = 1 * 2 = 2
iteration 2: j = 2 * 2 = 4
iteration 3: j = 4 * 2 = 8
iteration 4: j = 8 * 2 = 16
4) The code does not compile because (0 < x) && (x < 100) is not enclosed in a pair of parentheses. Any number of conditions can be placed in a single while using && (AND) or || (OR) operators but all those conditions should be placed inside the pair of paranthesis.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.