问题是要在多维数组(由用户选择的大小)中找到最大整数的位置,但必须使用 “公共静态位置locateLargest(double [] [] a)”,并且“位置”部分始终出现错误,我不知道要导入哪个库或做什么。
import java.util.*;
import java.text.*;
import java.io.*;
public class Exercise09_13 {
public static int rows=0;
public static int columns=0;
public static double maxValue=0;
public static void main(String[] args) {
int[][] myArray=getArray();
locateLargest(myArray);
}
public static int [][] getArray()
{
Scanner input = new Scanner(System.in);
System.out.println("Enter the dimensions of the array: ");
//Set values for array size
rows = input.nextInt();
columns = input.nextInt();
System.out.println("Enter the array: ");
//Set up arrays
int [][] m = new int[rows][columns];
for (int i = 0; i < m.length;i++)
{
for (int j = 0; j<m[i].length;j++)
{
m[i][j]=input.nextInt();
}
}
//return array
return m;
}
public static Location locateLargest(double[][] a)
{
double maxValue = a[1][1];
int position1, position2 = 0;
for (int i=0;i<rows;i++)
{
for(int j=0;j<columns;j++)
{
if (a[i][j]>maxValue)
{
maxValue=a[i][j];
position1=i;
position2=j;
}
}
}
System.out.println("The location of largest is: "+position1+", "+position2);
return new Location();
}
}