Java 299之输出二维数组中的最大值

来源:互联网 发布:苹果手机安装不了淘宝 编辑:程序博客网 时间:2024/04/30 11:16
</pre><pre class="java" name="code">import java.util.Scanner;public class Twodimensional {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubSystem.out.printf("Enter the number of rows and columns of the array:");Scanner input = new Scanner(System.in);int row = input.nextInt();int column = input.nextInt();double[][] d = new double[row][column];System.out.println("Enter the array:");for (int i = 0; i < row; i++)for (int j = 0; j < column; j++)d[i][j] = input.nextDouble();double max = 0;int r = 0, c = 0 ;for (int i = 0; i < row; i++)for (int j = 0; j < column; j++)if (d[i][j] > max) {max = d[i][j];r = i;c = j;}System.out.println("The location of the largest element is " + max+ " at (" + r + "," + c + ")");}}


截图:

 

0 0
原创粉丝点击