Java Programming Questions & Answers: part9



Software Programming : Java Programming QUESTIONS AND ANSWERS :: part9 : 11 to 15

Following Software Programming language Entrance Multiple choice objective type questions and answers will help you in Software Programming 2024 examinations :

11.Analyze the following code: public class Test { public static void main(String[] args) { int[] x = new int[5]; int i; for (i = 0; i < x.length; i++) x[i] = i; System.out.println(x[i]); } }

The program displays 0 1 2 3 4
The program displays 4
The program has a runtime error because the last statement in the main method causes ArrayIndexOutOfBoundsException
The program has syntax error because i is not defined in the last statement in the main method
The program displays 1 2 3 4 5.

12.You may or may not recall that the standard Java computing environment contains a Math class that includes a method called random() which returns a double as described below: public class Math { // The following method returns a double value with a // positive sign, greater than or equal to zero, // but less then 1.0, chosen "randomly" with approximately // uniform distribution from that range. public static double random() { ... } ... } Which one of the following expressions has a value that is equally likely to have any integer value in the range 3..8?

(6 * (int)Math.random()*100) + 3
(Math.random()*100 / (int) 6) + 3
(3..8 * Math.random()*100)
(int)(Math.random()*100 % 6) + 3
(6 / (int) Math.random()*100) + 3.

13.A proposed graduated state income tax applies the following rate schedule to net income after deductions: 0 --- if the net income is negative #2% --- on incomes less than $10,000 $200, plus 4% of excess over $10,000 --- for incomes between $10,000 and $20,000 (inclusive) $600, plus 6% of excess over $20,000 --- for incomes between $20,000 and $30,000 (inclusive) $1,200, plus 8% of excess over $30,000 --- for incomes greater than $30,000 You have been given a program that is supposed to calculate the tax on a given income in dollars. Which one of the following is the best set of test data on which to try out this program?

it makes no difference, any of the following are equally good!
2000, 4000, 6000, 8000, 10000, 12000, 14000
-10, 75, 10000, 15000, 20000, 25000, 30000, 40000
0, 10000, 20000, 30000, 40000
-5000, 0, 5000, 15000, 25000, 35000.

14.Suppose the following Java statements: char ch = ' '; try {do {ch = (char) System.in.read(); } while ( ch != 'G'); } catch(Exception i) { System.out.println(ch); } are executed and applied to the following input which is typed on the keyboard: g MnGyZ The final value of the variable ch will be:

'g'
' '
'n'
'G'
'y'.

More Java Programming QUESTIONS AND ANSWERS available in next pages

    Health is the greatest gift, contentment is the greatest wealth -Buddha
Identify your problems but give your power and energy to solutions- Tony Robbins