8.13 ** (The Location class)

来源:互联网 发布:琵琶 知乎 编辑:程序博客网 时间:2024/06/06 03:37
问题及代码:Main.javapackage first;    import java.util.Scanner;  public class Main {      public static void main(String[] args) {          int row, column ;          System.out                  .print("Enter the number of tows anf columns of the array: ");          Scanner cin = new Scanner(System.in);          row = cin.nextInt();          column = cin.nextInt();          System.out.println("Enter the array: ");          double [][]array = new double[row][column];        for(int i=0;i<row;++i)          {              for(int j=0;j<column;++j)              {                  array[i][j]=cin.nextDouble();              }          }          Location a=new Location(row,column,array);        Point x=new Point();        x=a.getmaxPoint();        System.out.println("The location of the largest element is "+(int)a.max +" at ("+(int)x.getx()+","+(int)x.gety()+")");      }  }Location.javapackage first;    public class  Location {      public int row, column;    double [][]array;    double max;    Point maxPoint=new Point();      Location (int a,int b,double a1[][])    {    row=a;    column=b;    array=a1;    }    Point getmaxPoint()    {    max=array[0][0];        for(int i=0;i<row;++i)          {              for(int j=0;j<column;++j)              {                  if(array[i][j]>max)                {                max=array[i][j];                maxPoint.setPoint(i,j);                }            }          }        return maxPoint;    }   }Point.javapackage first;public class Point {double a,b;Point(){a=0;b=0;}Point(double x,double y){a=x;b=y;}void setPoint(double x,double y){a=x;b=y;}double getx(){return a;}double gety(){return b;}}运行结果:

2 0