Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a complete Java class that will create a 2D array of randomly generated

ID: 673226 • Letter: 1

Question

1. Write a complete Java class that will create a 2D array of randomly generated ints with dimensions of 5 rows and 10 columns. Print the values of each cell to a 5x10 table.
(Note: a complete Java class means the code should compile and run without issue. Be sure the output displays a set of random ints formatted in 5 rows by 10 columns.

2. You have an int array named examScores that is 1000 elements in length.
Provide a single line of code that would sort the examScores. (Note: You do not need to provide the import statements supporting the line of code)

3.You have an int array named examScore that is 100 elements in length.Provide a single line of code that would search the examScores for values that are 50.

(Note: You do not need to provide the import statements supporting the line of code)

4. Describe an application that would be a good choice for using 3D array.
Provide the size of the array and the most likely data type. Provide the specific Java nested loop
you would use to populate the array elements with random values.

Explanation / Answer

1.

public class Array_2D {

   

    int arr[][];

    public Array_2D() {

        Random r=new Random(10);

         arr = new int[5][10];

         for(int i=0;i<5;i++)

         {

             for(int j=0;j<10;j++)

             {

                 arr[i][j]=(int)r.nextInt(10);

             }

         }

    }

      

     public void display()

     {

             for(int i=0;i<5;i++)

             {

                 for(int j=0;j<10;j++)

                 {

                     System.out.print(arr[i][j]+" ");

                 }

                 System.out.println("");

             }

      }

         public static void main(String[] args) {

         Array_2D s=new Array_2D();

         s.display();

      }

    }

2. Arrays.sort(examScores);

3.Arrays.binarySearch(examScores,50);

4.

3D array can be used to store response of 20 peoples which take participation in a quiz and having 10 questions and each of 10 questions have 4 different parts that need to be answered.

Hence an array of dimensions [20][10][4] will be better solution to store such type of information.

The size of array will be 20*10*4 which is 800*1=800 bytes. And as we have to have to store response of person in form of 1,2,3,4 so short will be best suitable data type.

Array element population :

for(int i=0;i<20;i++)

{

    for(int j=0; j<10;j++)

{

     for(int k=0;k<4;k++)

     arr[i][j][k]=1;

}

}