Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Fix code: I keep getting it wrong: / / package Grades; import java.util.Arrays; import java.util.Scanner; public class Grades { / / Studying values from the
Fix code: I keep getting it wrong:package Grades;
import java.util.Arrays;
import java.util.Scanner;
public class Grades
Studying values from the consumer
public static int readGrades
Scanner read new ScannerSystemin;
System.out.printInput the number of grades: ;
int length read.nextInt;
int grades new intlength;
for int i ; i length; i
System.out.printInput i th grade: ;
int grade read.nextInt;
gradesi grade;
read.close;
return grades;
Calculating the sum of grades in the array
public static int sumint arr
int sum ;
for int i ; i arr.length; i
sum sum arri;
return sum;
Calculating the sum of grades at the first and last index
public static int sumint arr, int firstIndex, int lastIndex
return arrfirstIndex arrlastIndex;
Calculating the average of grades in the array
public static double averageint arr
int sum ;
for int i ; i arr.length; i
sum sum arri;
return double sum arr.length;
Finding the maximum grade in the array of grades
public static int maxValueint arr
int max arr;
for int i ; i arr.length; i
if max arri
max arri;
return max;
Finding the minimum grade in the array of grades
public static int minValueint arr
int min arr;
for int i ; i arr.length; i
if min arri
min arri;
return min;
calculateAverage method that takes an array of int as input and returns the average of its elements.
public static double calculateAverageint array
if array null array.length
throw new IllegalArgumentExceptionArray is null or empty";
double sum ;
for int num : array
sum num;
return sum array.length;
Java function that calculates the number of elements below a certain average in an array
public static int countElementsBelowAverageint array
if array null array.length
throw new IllegalArgumentExceptionArray is null or empty";
double average averagearray;
int count ;
for int num : array
if num average
count;
return count;
Java function that calculates the number of elements above a certain average in an array
public static int countElementsAboveAverageint array
if array null array.length
throw new IllegalArgumentExceptionArray is null or empty";
double average averagearray;
int count ;
for int num : array
if num average
count;
return count;
Here's a simple function in Java that reverses an array
public static int reverseArrayint array
if array null array.length
throw new IllegalArgumentExceptionArray is null or empty";
int reversedArray new intarraylength;
for int i ; i array.length; i
reversedArrayi arrayarraylength i;
return reversedArray;
If you want to rotate elements in an array to a given count and return the rotated array, you can use the following Java function:
public static int rotateArrayint array, int positions
if array null array.length
throw new IllegalArgumentExceptionArray is null or empty";
int n array.length;
positions positions n; Adjust for positions larger than array length
int rotatedArray new intn;
for int i ; i n; i
int newIndex i positions n;
rotatedArraynewIndex arrayi;
return rotatedArray;
Main approach
public static void mainString args
int arr;
arr readGrades;
System.out.printlnSum: sumarr;
System.out.printlnSum of the first index and last index values: sumarr arr.length ;
System.out.printlnAverage of grades: averagearr;
System.out.printlnMaximum Grade: maxValuearr;
Sys
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started