The second problem of software engineering work P37
Import Java.util.Arrays;
Suppose the incoming array is {1,-2,3,-2,5,1}
public class Test0000 {
public void Max (int[] a) {
int b[] = new INT[10];
int c[] = new INT[10];
int d[] = new INT[10];
int e[] = new INT[10];
int f[] = new INT[10];
int g[] = new INT[5];
for (int i = 0; i < a.length-1; i++) {
B[i] = A[i] + a[i + 1];
if (i + 2 <=5) {
C[i] = A[i] + a[i + 1] + a[i + 2];
}else{
Continue
}
if (i + 3 <= a.length-1) {
D[i] = A[i] + a[i + 1] + A[i + 2] + a[i + 3];
}else{
Continue
}
if (i + 4 <= a.length-1) {
E[i] = A[i] + a[i + 1] + A[i + 2] + A[i + 3] + a[i + 4];
}else{
Continue
}
if (i + 5 <=a.length-1) {
F[i] = A[i] + a[i + 1] + A[i + 2] + A[i + 3] + a[i + 4]+ A[i + 5];
}else{
Continue
}
}
Arrays.sort (a);
Arrays.sort (b);
Arrays.sort (c);
Arrays.sort (d);
Arrays.sort (e);
Arrays.sort (f);
G[0] = b[9];
G[1] = c[9];
G[2] = d[9];
G[3] = e[9];
G[4] = f[9];
Arrays.sort (g);
System.out.println (G[4]);
}
public static void Main (string[] args) {
int a[] = {1,-2, 3,-2, 5, 1};
New Test0000 (). Max (a);
}
}
Software Engineering P37 Exercise Two program code