Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
package sum;
import java.util.Scanner;
public class Main {

  
    public static void main(String[] args) {
     Scanner input = new Scanner(System.in);
     int a;
     int n  ;
     System.out.println("enter an integer :");
     a = input.nextInt();

     System.out.println("enter an integer :");
     n= input.nextInt();
       	System.out.println(sum(a,n));
    }
  public static  double sum(int n,double []a)
{
    if(n ==0)
        return n;
  return sum(a,n-1)+a[n-1];

}

    private static double sum(double[] a, int i) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    }

the programe have an error in the line (System.out.println(sum(a,n));)??
I really sorry i dont know how i must call sum using Main.sum(a, n) and write it i am amateur
thanks:rose:
Posted
Updated 13-Feb-10 8:45am
v4

You do not have a sum(int i1, int i2) method in your class.
 
Share this answer
 
Did you read my previous answer? You have two overloads of sum() and yet your call does not match either of them, so the compiler will reject it.
 
Share this answer
 
mf_arian wrote:
System.out.println(sum(a,n));


I think it is better to call sum using
Main.sum(a, n)

Also make sure the signature matches properly. I can see the signature is different.

;)
 
Share this answer
 
You have defined a function sum() which takes as input an integer and an array of doubles, and returns a double. However in your call you are passing two integers as input parameters; obviously this does not match. If you are having trouble understanding this then I suggest you go to The Java Tutorials[^] and spend some time learning the language basics.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900