Given an expression like Sigma x=a to b x Sigma y = a to x y. Compute its value where the inputs a and b are integers and b>=a.
Please comment if you find any mistake.
public class ComputeSigma {
static int testcase11 = 6;
static int testcase12 = 12;
public static void main(String args[]){
ComputeSigma
testInstance= new ComputeSigma();
int result =
testInstance.computeSigma(testcase11,testcase12);
System.out.println(result);
}
//write your code
here
public int computeSigma(int a, int b){
int num=0;
for(int i=a;i<=b;i++)
{
int sum=0;
for(int j=a;j<=i;j++)
{
sum=sum+j;
}
num=num+i*sum;
}
return num;
}
}
Please comment if you find any mistake.
No comments:
Post a Comment