JAVA 7.8
- import java.util.Scanner;
- public class Sumarray {
- public static void main(String[] args) {
- int[] iBucket = new int[10];
- double [] dBucket = new double[10];
- Scanner input = new Scanner(System.in);
- int i;
- for ( i=0 ; i<10 ; i++ )
- {
- iBucket[i] = input.nextInt();
- dBucket[i] = input.nextDouble();
- }
- System.out.println(sum (iBucket));
- System.out.println(sum (dBucket));
- }
- public static int sum (int[] array )
- {
- int j,iSum;
- iSum = 0;
- for ( j=0 ; j<10 ; j++ )
- iSum += array[j];
- return iSum;
- }
- public static double sum (double[] array )
- {
- int j;
- double dSum = 0.0;
- for ( j=0 ; j<10 ; j++ )
- dSum += array[j];
- return dSum;
- }
- }
Overloading Methods
留言
張貼留言