All of these are Java questions 1 Which of the following is
All of these are Java questions:
1) Which of the following is not legal in a method definition?
a) Multiple parameter variables
b) Parameter variable data types
c) One return value
d) Multiple return values
2) The Math.ceil method in the Java standard library takes a single value x and returns the smallest integer that is greater than or equal to x. Which of the following is true about Math.ceil(56.75)?
a) The argument is 56.75, and the return value is 57.
b) The argument is 56.75, and the return value is 56.
c) The argument is 57, and the return value is 56.75.
d) The argument is 56, and the return value is 56.75.
3) What is wrong with the following code?
a) Illegal return type
b) Invalid parameter variable type
c) No return statement
d) Invalid scope of variable used in return statement
4) For the given code snippet, which of the following statements is true?
a) The code snippet executes and displays “Pay rate: 40.0”
b) The code snippet executes and displays “Pay rate: 44.0”
c) The code snippet executes and displays “Pay rate: 0.0”
d) There is no output because the program does not compile
5) What is the result of executing this code snippet?
a) The code snippet does not give any output.
b) The code snippet displays all the marks stored in the array without any redundancy.
c) The code snippet causes a bounds error.
d) The code snippet executes an infinite loop.
6) What is the valid range of index values for an array of size 10?
a) 0 to 10
b) 1 to 9
c) 1 to 10
d) 0 to 9
7) Which one of the following statements is correct about the given code snippet?
a) The for loop initializes all the elements of the array.
b) The for loop initializes all the elements except the first element.
c) The for loop initializes all the elements except the last element.
d) The for loop initializes all the elements except the first and last elements.
8) What is the result of the following code?
a) The elements of the array values are initialized to zero.
b) The elements of the array element are initialized to zero.
c) The first element of the array values is initialized to zero.
d) The array values is not modified.
9) Consider the following code snippet:
What is the value of numarray[1][2] after the code snippet is executed?
a) 2
b) 5
c) 3
d) 4
10) Which one of the following statements is the correct definition for a two-dimensional array of 20 rows and 2 columns of the type integer?
a) int[][] num = new int[20][2];
b) int[][] num = new int[2][20];
c) int[][] num = new int[20,2];
d) int[][] num = new int[2,20];
Solution
Hi, I have answered first 5 questions.
Please post other questions in separate post.
Please let me know in case if any issue.
1) Which of the following is not legal in a method definition?
d) Multiple return values
2) The Math.ceil method in the Java standard library takes a single value x and returns the smallest integer that is greater than or equal to x. Which of the following is true about Math.ceil(56.75)?
a) The argument is 56.75, and the return value is 57.
3) What is wrong with the following code?
public static int count(String s)
{
for (int i = 0; i < s.length(); i++)
{
int cnt = 0;
if (Character.isDigit(s.charAt(i)))
{
cnt++;
}
}
return cnt;
}
d) Invalid scope of variable used in return statement
4) For the given code snippet, which of the following statements is true?
public static double raise(double rate)
{
double newPayRate = rate * 1.1;
return newPayRate;
}
public static void main(String[] args)
{
double rate = 40.0;
double newPayRate = 0.0;
newPayRate = raise(rate);
System.out.println(\"Pay rate: \" + newPayRate);
}
b) The code snippet executes and displays “Pay rate: 44.0”
5) What is the result of executing this code snippet?
int[] marks = { 90, 45, 67 };
for (int i = 0; i <= 3; i++)
{
System.out.println(marks[i]);
}
c) The code snippet causes a bounds error.


