简体   繁体   English

在同一个类中调用一个方法

[英]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. 我的错误即时消息是“线程'main'中的异常java.lang.NoClassDefFoundError:dProb(错误名称:DProb)”,虽然它不是编译错误。 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. 您的班级名称是DProb,并且正在输入dProb。

Also why are you returning 0.0 in HyperGeometric as you Probx variable is 0.0.. 另外,当Probx变量为0.0时,为什么还要在HyperGeometric中返回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. 造成这种情况的最可能原因是您的.java文件称为dProb.java。 The class name and file name must match! 类名和文件名必须匹配!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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