首页 > 代码库 > HW7.13

HW7.13

技术分享

 

 1 import java.util.Scanner; 2  3 public class Solution 4 { 5     public static void main(String[] args) 6     { 7         Scanner input = new Scanner(System.in); 8         System.out.print("Enter the number of rows and columns of the array: "); 9         int row = input.nextInt();10         int column = input.nextInt();11 12         double[][] array = new double[row][column];13 14         System.out.println("Enter the array: ");15         for(int i = 0; i < row; i++)16             for(int j = 0; j < column; j++)17                 array[i][j] = input.nextInt();18 19         int[] maxElement = locateLargest(array);20         System.out.println("The location of the largest element is at (" + maxElement[0] + ", " + maxElement[1] + ")");21     }22 23     public static int[] locateLargest(double[][] a)24     {25         int[] maxLocation = new int[2];26         double maxValue = http://www.mamicode.com/a[0][0];27 28         for(int i = 0; i < a.length; i++)29             for(int j = 0; j < a[0].length; j++)30                 if(a[i][j] > maxValue)31                 {32                     maxValue =http://www.mamicode.com/ a[i][j];33                     maxLocation[0] = i;34                     maxLocation[1] = j;35                 }36 37         return maxLocation;38     }39 }

 

HW7.13