Created
February 13, 2014 05:15
-
-
Save JorgeOlvera/8970117 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Write a method public static int max(int[][] a)that | |
returns the maximum value in the 2d parameter array a. | |
*/ | |
import java.util.Scanner; | |
public class maximumArray{ | |
public static int max(int[][] my2d) { | |
Scanner input = new Scanner(System.in); | |
int para1 = input.nextInt(); | |
int para2 = input.nextInt(); | |
int[][] my2d = new int[para1][para2]; | |
for (i=0; i<my2d.length; i++){ | |
for (j=0; j<my2d[i].length; j++){ | |
my2d[i][j] = input.nextInt(); | |
int largest = max(my2d); | |
System.out.println(largest); | |
} | |
} | |
return biggest | |
} | |
public static int max(int[][] my2d) | |
{ | |
Scanner input = new Scanner (System.in); | |
int max = my2d[0][0]; | |
int x =0; | |
int y=0; | |
for (int i= 0;i <my2d.length;i++) | |
{ | |
for (int j =0; j<my2d[i].length;j++) | |
{ | |
if (my2d[i][j] > max) | |
{ | |
max = my2d[i][j]; | |
x =i; | |
y =j; | |
} | |
} | |
} | |
int z = my2d[x][y]; | |
return z; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment