軟體工程P37習題二程式碼

來源:互聯網
上載者:User

標籤:

 //軟體工程作業P37第二題
import java.util.Arrays;
//假設傳入的數組是{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);
}
}

軟體工程P37習題二程式碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.