Sry for being nubby. barely one year of programming:(
Basically, I'm trying to call a method from another class, and make it print on screen.
public class Show{
public static void main(String[] args) {
int x=1;
int a=4;
int b=2;
x = Combination.comb(a,b);
System.out.println(x);
} }
This is the Combination class that i am trying to call. first method does factorials, second method uses factorials to do combination
public class Combination {
public int factorial(int x) {
int result=1;
for(int i=1;i<=x;i++){
result=i * result;
}
return result;
}
public int comb(int n, int k)
{
int combin=1;
int temp4=1;
int temp1 = factorial(n);
int temp2 = factorial(k);
temp4 = n-k;
int temp3 = factorial (temp4);
combin = temp1/(temp2 * temp3);
return combin;
}
}


Ask A New Question
Reply





MultiQuote






|