简体   繁体   中英

call a method inside the same class

Can someone please explain why this is not working? can you not run a method that belongs to the same class? I have been going at this for a while and my brain is just starting to hurt. Thank you in advance.

My error im getting is "Exception in thread 'main' java.lang.NoClassDefFoundError: dProb (wrong name:DProb)" its not a compile error though. its when i try to pass the variables.

public class DProb{
    public static double Combinations(long N, long X){
        double comb = 0.0;
        long n = N;
        long r = X;
        long denom;
        if(n==r || r == 0)
            n = 1;
        else{
            denom = n-r;
            for(long i = n; i > denom; i--){
                if (i == n){}
                else
                    n *= i;
            }
            for (long i = r; i > 0; i--){
                if (i == r){}
                else
                    r *= i;
            }
            n = n/r;
        }
        comb = n;
        return comb;
    }

    public static double HyperGeometric(long Np, long Xp, long N, long X){
        double probX = 0.0;
        double leftNum = Combinations(N,X);

        return probX;
    }
}

While calling from you main function make sure the Class name is right.

As per your Error it seems Your Class name is having issue.

Your class name is DProb and you are typing dProb.

Also why are you returning 0.0 in HyperGeometric as you Probx variable is 0.0..

public class DProb{

needs to be

public class dProb{

The most likely reason for this is your .java file is called dProb.java. The class name and file name must match!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM