HW7.13
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 = 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 = a[i][j]; 33 maxLocation[0] = i; 34 maxLocation[1] = j; 35 } 36 37 return maxLocation; 38 } 39 }
以上是关于HW7.13的主要内容,如果未能解决你的问题,请参考以下文章