List the errors in the following array declarations A int in

List the errors in the following array declarations.

A. int intArray[] = new double[10];

B. int intArray[] = new int[1.5];

C. double[] doubleArray = new double[-10]

D. int intMatrix[] [] = new int[10];

- Write a method selectRandom that expects an array of integers as a parameter. The method should return the value of an array element at a randomly selected position.

Solution

Q1.)A.) for an int type, you can create only int array. So format should be like

int intArray[] = new int[10].

B.) Size of an array can only be integer. It can\'t be of double value. It will give compile time error : possible loss of precision, found double, required int

C.) It will not give any compile time error but it will give run time exception as -ve values are not allowed for array size.

D.) For 2-D array definition, you must create a 2-D array.

Hope it helps, do give your response.

List the errors in the following array declarations. A. int intArray[] = new double[10]; B. int intArray[] = new int[1.5]; C. double[] doubleArray = new double[

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site