/*
* Copyright (c) 2015, 烟台大学计算机学院
* All rights reserved.
* 文件名称:test.java
* 作 者:王元阳
* 完成日期:2015 年 10 月 20 日
* 版 本 号:v1.0
*问题描述: 构造一个地址类,建立一个二维数组,依次输入各个元素,最后返回最大的元素的地址 。
*/
import java.util.Scanner;
public class Location {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("Enter the rows an columns of the array:");
int a = input.nextInt();
int b = input.nextInt();
Location1 location1 = new Location1(a, b);
System.out.println("Enter the array:");
int i , j , c = 0, d = 0;
double maxValue = 0;
for (i=0; i < a; i++) {
for (j=0; j < b; j++) {
double x = input.nextDouble();
if (maxValue < x) {
maxValue = x;
c = i;
d = j;
}
}
}
System.out.println("The location of the largest element is " + maxValue
+ " at (" + c + "," + d + ")");
}
}
class Location1 {
int rows;
int columns;
Location1() {
rows = 1;
columns = 1;
}
Location1(int newRows, int newColumns) {
rows = newRows;
columns = newColumns;
}
}