KENNY
Lv 5

求解 JAVA 陣列 問題

試著將

int[]a=(30.50.7.90.4.8.60.2.1.10);

int[]b={60.80.4.3.10.7.40.9.50.6};

int[]c=hew int[10];

試著將a陣列與b陣列的值,逐個相加,並存至c陣列

並將相加後的直 反序印出

例如 原本是 90.130.11.93.14.15.100.11.51.16

將印出 16,51,11,100,15,14,93,11,130,90 (要有 , )

我想看看 for 和 while 的寫法~

謝謝!

Update:

import java.util.Scanner;

public class ok {

public static void main(String[] args) {

1 Answer

Rating
  • 9 years ago
    Favorite Answer

    int[]c=hew int[10];

    int[] c = new int[10];

    for(int i=0;i<a.length;i++)

     c[i] = a[i] + b[i];

    //或

    int i = 0;

    while(i<b.length){

     c[i] = a[i] +b[i];

     i++;

    }

    //順序

    for(int t : c)

     System.out.print(t + ",");

    //反序

    int j = c.length-1;

    while(j>=0){

     System.out.print(c[j] + ",");

     j--;

    }

Still have questions? Get your answers by asking now.