I am working on a java code that calculates the average of an array and it is working perfectly in serving its purpose but I want to modify it to be a 2D array (Two-dimensional).
import java.util.*;
public class Test3{
public static void main(String [] args){
Scanner adnan = new Scanner(System.in);
System.out.println("Enter the length of the array : ");
int length = adnan.nextInt();
int [] input = new int [length];
System.out.println("Enter Numbers : ");
for ( int i = 0; i < length; i++){
input [i] = adnan.nextInt();
}
float average = average(input);
System.out.println("Average of all numbers in the array : " + average);
adnan.close();
}
public static float average(int [] input){
float sum = 0f;
for ( int number : input){
sum = sum + number;
}
return sum / input.length;
}
}
any help would be really appreciated because I am not too good at 2D arrays.