Anonymous
Anonymous asked in 電腦及互聯網程式編寫及設計 · 1 decade ago

請幫我修改java,method,array,加數

public class CeltoFah {

public static void main(String[] args) {

int ary[] = {1,2,3,4,5,6,7,8};

int sum = 0;

sum = calSum(ary);

System.exit(0);

return sum;

}// end main

public static int calSum(int a[]){

int a =0;

for(a; a < ary.length; a++){

sum += a;}

System.out.println("The sum is " + sum);

return ary;

}

}

1 Answer

Rating
  • ?
    Lv 5
    1 decade ago
    Favorite Answer

    don't know what's with you. just fix some error. pls try

    import java.io.*;

    public class CeltoFah {

    public static void main(String[] args) {

    int ary[] = {1,2,3,4,5,6,7,8};

    int sum = 0;

    sum = calSum(ary);

    System.exit(0);

    // return sum;

    }// end main

    public static int calSum( int [] a ){

    int iSum = 0;

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

    iSum += a[ i ];}

    System.out.println( "The sum is " + iSum );

    return iSum;

    }

    }

Still have questions? Get your answers by asking now.