SCJP Module-1 Question-12


 

SCJP Module-1 Question-12

The given program check your core java concepts and helps for SCJP examination.

The given program check your core java concepts and helps for SCJP examination.

Given a sample code:

1 public class Sample1 {
2 public static void main(String[] args) {
3 for (int i = 0; i < 2; i++) {
4 System.out.println(getValue(101));
}}

5 public static int getValue(int i) {
6 return (short) (Math.random() * i);
}}

What will be the result of above code ?

(1) Compilation fails because of an error at line 4
(2) Compilation fails because of an error at line 5
(3) Compilation fails because of an error at line 6
(4) Compile and run successfully with with two random number as output

Answer

(4)

Ads