Write Java code to declare and initialize an array of assign

Write Java code to declare and initialize an array of assignment scores for 10 students. (Scores should range from 0 to 100.) Now, write Java code to declare and initialize an array of student names.

Here are some questions to ask yourself as you write the code:

What should the data type of the array be (i.e. what kind of data does it store)?

What should the size of the array be?

Should I declare and initialize in one step? Or should I use multiple lines of code?

Example - One Step:

int[] oddNums = {1, 3, 5, 7, 11, 13, 15, 17, 19};

Example - Multiple Lines of Code:
int[] oddNums = new int[9];
oddNums[0] = 1;
oddNums[1] = 3;

oddNums[8] = 19;


Draw a picture in memory of your two arrays after initialization.

Calculate the mean for your scores array.

Write a line of code to call the printGreater() method on your scores.

Solution

Please find my implementation.

Please let me know in case of any issue.

public class ArrayProgram {

  

   public static void printGreater(int[] scores){

      

       int max = scores[0];

      

       for(int i=1; i<scores.length; i++){

           if(scores[i] > max)

               max = scores[i];

       }

      

       System.out.println(\"Greatest Score: \"+max);

   }

   public static void main(String[] args) {

       // declaring and initializing score array

       int[] scores = {77, 68, 80, 81, 88, 85, 74, 82,89, 90};

       // declaring and initializing name array

       String[] names = {\"Pravesh Kuamr\", \"Alex\", \"Bob\", \"Pintu K\", \"Richadson M\",

               \"Mukesh\", \"Ram\", \"K Rahul\",\"Kohli V\", \"Test Name\"};

      

       // calculating sum of all scores to calculate mean

       double sum = 0;

       for(int i=0; i<scores.length; i++)

           sum = sum + scores[i];

      

       System.out.println(\"Mean: \"+sum/scores.length);

      

       // calling printGreater method

       printGreater(scores);

      

      

   }

}

/*

Sample run:

Mean: 81.4

Greatest Score: 90

*/

Write Java code to declare and initialize an array of assignment scores for 10 students. (Scores should range from 0 to 100.) Now, write Java code to declare an
Write Java code to declare and initialize an array of assignment scores for 10 students. (Scores should range from 0 to 100.) Now, write Java code to declare an

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site