gpt4 book ai didi

java - 简单的实例变量问题

转载 作者:行者123 更新时间:2023-12-02 03:09:23 24 4
gpt4 key购买 nike

我正在从事一个涉及椭圆曲线的小型个人项目,并且我在曲线的实例变量方面遇到了一些困难。变量在 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
}

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

关于java - 简单的实例变量问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41275400/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com