-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjwelch_module_11.java
More file actions
79 lines (75 loc) · 2.69 KB
/
jwelch_module_11.java
File metadata and controls
79 lines (75 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* Joshua Welch
* Module 11
* Array location
*/
import java.util.Random;
import java.util.Arrays;
public class jwelch_module_11 {
//double framework for array location
private static int [] locateLargest (double [][] array) {
int [] largestLocation = new int[2];
double largestElement = 0;
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
if (array[i][j] > largestElement) {
largestElement = array[i][j];
largestLocation[0] = i;
largestLocation[1] = j;
}
}
}
return largestLocation;
}
//int framework for array location
private static int [] locateLargest (int [][] array) {
int [] largestLocation = new int[2];
int largestElement = 0;
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
if (array[i][j] > largestElement) {
largestElement = array[i][j];
largestLocation[0] = i;
largestLocation[1] = j;
}
}
}
return largestLocation;
}
//main!!!
public static void main(String[] args) {
int rows = 5;
int columns = 5;
Random rand = new Random();
//make int array
int[][] array = new int[rows][columns];
for (int i = 0; i<rows; i++) {
for (int j = 0; j < columns; j++) {
array[i][j] = rand.nextInt(100);
}
}
//make double array
double[][] array_2 = new double[rows][columns];
for (int i = 0; i<rows; i++) {
for (int j = 0; j < columns; j++) {
array_2[i][j] = rand.nextInt(100);
}
}
//check int array
int[] intLocation = locateLargest(array);
//check double array
int[] doubleLocation = locateLargest(array_2);
//print int array
System.out.println("----------INT ARRAY----------");
for (int i = 0; i < rows; i++) {
System.out.println(Arrays.toString(array[i]));
}
System.out.println("The spot that you seek is " + intLocation[0]+","+intLocation[1] + " which is: " + array[intLocation[0]][intLocation[1]]);
//print double array
System.out.println("----------DOUBLE ARRAY----------");
for (int i = 0; i < rows; i++) {
System.out.println(Arrays.toString(array_2[i]));
}
System.out.println("The spot that you seek is " + doubleLocation[0]+","+doubleLocation[1] + " which is: " + array_2[doubleLocation[0]][doubleLocation[1]]);
}
}