Test Preparation on JAVA- Data Types, Variables and Arrays-2
1.
What will be the output of the following Java code?
$ javac average.java
$ java average
16.46666666666667
2.
What will be the output of the following Java statement?
Explanation: For floating point literals, we have constant value to represent (10/0.0) infinity either positive or negative and also have NaN (not a number for undefined like 0/0.0), but for the integral type, we don’t have any constant that’s why we get an arithmetic exception.
3.
What will be the output of the following Java code?
Explanation: Operator ++ has more preference than *, thus g becomes 4 and when multiplied by 8 gives 32. output:
$ javac increment.java
$ java increment
32
4.
What will be the output of the following Java code?
$ javac area.java
$ java area
301.5656
5.
What will be the output of the following Java program?
$ javac array_output.java
$ java array_output
i i i i i