-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarlos.java
More file actions
53 lines (37 loc) · 925 Bytes
/
Copy pathCarlos.java
File metadata and controls
53 lines (37 loc) · 925 Bytes
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
package twoDArray;
public class Carlos {
public static void main(String[] args) {
int[][] a = new int[4][7];
int[][] b = { { 1, 2, 3, 4 }, { 9, 8, 7, 6, 5 }, { 7, 6, 2, 5, 8 } };
genrate2dArray(a);
for (int i = 0; i < b.length; i++) {
if (!isSorted(b[i])) {
System.out.println(getSum(b[i]));
}
}
}
private static void genrate2dArray(int[][] a) {
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
a[i][j] = (int) (Math.random() * (10 + 1 - 0)) + 0;
}
}
}
static boolean isSorted(int[] a) {
boolean result = true, result2 = true;
for (int i = 0; i < a.length - 1; i++)
if (a[i] < a[i + 1])
result = false;
for (int i = 0; i < a.length - 1; i++)
if (a[i] > a[i + 1])
result2 = false;
return result || result2;
}
private static int getSum(int[] is) {
int sum = 0;
for (int i : is) {
sum += i;
}
return sum;
}
}