Introduction to Java Programming编程题8.13<返回二维数组中最大值及下标>
来源:互联网 发布:平台介绍淘宝代理开店 编辑:程序博客网 时间:2024/06/05 20:10
/*Enter the number of rows and columns of the array: 3 4Enter the array: 11 33.5 88.1 40 -2.2 -10.1 -201.11 2.22 3.3 4.4The location of the largest element is 88.1 at (0, 2) */import java.util.Scanner;public class FindMaxValue { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the number of rows and columns of the array: "); final int ROW = input.nextInt(); final int COLUMN = input.nextInt(); double[][] matrix = new double[ROW][COLUMN]; System.out.println("Enter the array: "); for (int i = 0, j; i < matrix.length; i++) for (j = 0; j < matrix[i].length; j++) matrix[i][j] = input.nextDouble(); int[] max = findMax(matrix); System.out.println("The location of the largest element is " + matrix[max[0]][max[1]] + " at (" + max[0] + ", " + max[1] + ")"); } public static int[] findMax(double[][] matrix) { int[] max = new int[2]; int k = 0; double maxValue = matrix[k][k]; for (int i = 0, j; i < matrix.length; i++) { for (j = 0; j < matrix[i].length - 1; j++) if (maxValue < matrix[i][j + 1]) { max[k] = i; max[k + 1] = j + 1; } } return max; }}
0 0
- Introduction to Java Programming编程题8.13<返回二维数组中最大值及下标>
- Java:<返回二维数组中最大值及下标>
- JAVA获取数组中最大值及其下标
- introduction to Java Programming 编程题5.3<回文整数>
- Introduction to Java Programming编程题5.6<打印数字三角形>
- Introduction to Java Programming编程题5.13<数列求和>
- Introduction to Java Programming编程题5.14<计算数列>
- Introduction to Java Programming编程题5.17<01矩阵>
- Introduction to Java Programming编程题5.26<回文素数>
- Introduction to Java Programming编程题5.27<反素数>
- Introduction to Java Programming编程题5.29<掷骰子游戏>
- Introduction to Java Programming编程题5.28<梅森素数>
- Introduction to Java Programming编程题5.30<双素数>
- Introduction to Java Programming编程题9.1<检查SSN>
- Introduction to Java Programming编程题9.2<检查子串>
- Introduction to Java Programming编程题7.6<两个矩阵相乘>
- Introduction to Java Programming编程题9.3<检验密码>
- Introduction to Java Programming编程题9.8<二进制转十进制>
- C++ 入门教程(六) 基本数据类型和变量
- ion-tabs接口文档:Delegate: $ionicTabsDelegate
- C++中的继承和组合区别使用
- Excel自定义格式详解
- MII、GMII、RMII、SGMII、XGMII、XAUI、Interlaken
- Introduction to Java Programming编程题8.13<返回二维数组中最大值及下标>
- data 纵转横
- 发短信机制
- this指针学习笔记
- 3.0.3、Docker废弃的特性
- HDU 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活
- Android 生成桌面图标
- 服务器安全狗导致FTP链接、上传失败 解决方法
- 关于Shader wants normals, but the mesh New Game Object doesn't have them的问题