8.13 ** (The Location class)
2015-10-27 20:28
183 查看
问题及代码: Main.java package 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.java package 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.java package 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; } } 运行结果:
相关文章推荐
- Session和Cookie
- 移植BOA到mini2440
- [HZWER]藏妹子之处
- 为什么使用模块?
- 约瑟夫
- 洛谷P1541/CODEVS1068 乌龟棋
- RGB和CMYK配色表
- HTML基础知识
- Java的集合容器(下)
- POI不同版本替换Word模板时的问题
- bzoj4027: [HEOI2015]兔子与樱花
- XRay3
- 03-树3 Tree Traversals Again
- 关于硬链接
- C语言 - 冒泡排序算法(交换排序) 从大到小
- Java并发编程--同步容器
- composer autoload
- hdu 4610 Cards(暴力+miller-rabin)
- Machine Learning学习路线
- 记录给nginx增加模块过程中碰到的问题