Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 简单实例变量问题_Java_Instance Variables - Fatal编程技术网

Java 简单实例变量问题

Java 简单实例变量问题,java,instance-variables,Java,Instance Variables,我正在做一个涉及椭圆曲线的小型个人项目,我对曲线的实例变量有点困难。在main方法中正确打印变量,但print方法始终返回每个变量等于0的值。有人想办法解决这个问题吗?请容忍我,我知道这是一个相当小的问题 public class ellipticcurve { public int A, B, p; public ellipticcurve(int A, int B, int p) { A = this.A; B = this.B; p = this.p; /

我正在做一个涉及椭圆曲线的小型个人项目,我对曲线的实例变量有点困难。在main方法中正确打印变量,但print方法始终返回每个变量等于0的值。有人想办法解决这个问题吗?请容忍我,我知道这是一个相当小的问题

public class ellipticcurve {

public int A, B, p;
public ellipticcurve(int A, int B, int p) {
    A = this.A;
    B = this.B;
    p = this.p;
    // E:= Y^2 = X^3 + AX + B
}

public static boolean isAllowed(int a, int b, int p) { 
    return ((4*(Math.pow(a, 3)) + 27*(Math.pow(b, 2)))%p != 0);
}

public static void printCurve(ellipticcurve E) {
    System.out.println("E(F" + E.p + ") := Y^2 = X^3 + " + E.A + "X + " + E.B + ".");
}

public static void main(String[] args) {
    ArgsProcessor ap = new ArgsProcessor(args);
    int a = ap.nextInt("A-value:");
    int b = ap.nextInt("B-value:");
    int p = ap.nextInt("Prime number p for the field Fp over which the curve is defined:");

    while (isAllowed(a, b, p) == false) {
        System.out.println("The parameters you have entered do not satisfy the "
                + "congruence 4A^3 + 27B^2 != 0 modulo p.");
        a = ap.nextInt("Choose a new A-value:");
        b = ap.nextInt("Choose a new B-value:");
        p = ap.nextInt("Choose a new prime number p for the field Fp over which the curve is defined:");
    }

    ellipticcurve curve = new ellipticcurve(a, b, p);
    System.out.println(curve.A + " " + curve.B + " " + curve.p);
    printCurve(curve);
    System.out.println("The elliptic curve is given by E(F" + p 
            + ") := Y^2 = X^3 + " + a + "X + " + b + ".");
}

在构造函数中,它应该是这样的

public ellipticcurve(int A, int B, int p) {
   this.A = A;
    this.B = B;
    this.p = p;
     // E:= Y^2 = X^3 + AX + B  
}
而不是

public ellipticcurve(int A, int B, int p) {
   A = this.A;
   B = this.B;
    p = this.p;
   // E:= Y^2 = X^3 + AX + B
}

您正在将实例变量分配给构造函数中传递的变量,因此实例变量将被初始化为构造函数中的默认值

public ellipticcurve(int A, int B, int p) {
   this.A = A;
    this.B = B;
    this.p = p;
     // E:= Y^2 = X^3 + AX + B  
}
而不是

public ellipticcurve(int A, int B, int p) {
   A = this.A;
   B = this.B;
    p = this.p;
   // E:= Y^2 = X^3 + AX + B
}
您正在将实例变量分配给在构造函数中传递的变量,以便将实例变量初始化为其默认值