gpt4 book ai didi

java - 将一个数组分配给另一个数组

转载 作者:行者123 更新时间:2023-12-01 18:34:36 24 4
gpt4 key购买 nike

将函数(是一个数组)的返回值分配给数组时遇到一些问题。

public static int[] calculeaza_P(int poli[], int n, int k, int p) {
int P[] = new int[n];
//calculam mesajul, P(0)....P(n-1) se obtin inlocuind in polinom cu valoare
for (int i = 0; i < n; i++) {
//initializare cu a0//elementul liber din polinom
P[i] = get_unsemnificative_coef(poli, 0);
//puterile i....i^k-1
for (int j = 1; j < k; j++) {
//P(x)=(a_1)*(i^1)+....(a_k-1)*(i^k-1)
P[i] = P[i] + get_unsemnificative_coef(poli, j) * (int) Math.pow(i, j);
}
//modulo p
P[i] = P[i] % p;

}
return P;
}

在我的主要方法中,我有

 public static void main(String[] args) {
int p = 7;// nr prim pe l biti, 2^l<=p<=2^(l-1)
int poli[] = new int[]{2, 3, 4};//a_k-1......a1,a0 numere <p
int k = poli.length;//lungimea sirului
int s = 1;//nr erori de corectat
int n = k + 2 * s;//nr de P(x), sau lungimea lui C'

System.out.println("Polinomul initial:" + print_poly(poli));
////////
//generarea P(x) si mesajului codificat
System.out.println("De la dreapta la stanga, P(x):");

int[] P = new int[n];
P= calculeaza_P(poli[], n, k, p);

for (int i = 0; i < P.length; i++) {
System.out.print("P(" + i + ")=" + P[i] + " ");
}
System.out.println();
System.out.println();
// System.out.println("Mesaj initial corect: " + mesaj);
//schimb 1 bit
int poz = 2;
//int mesajgresit = S_SchimbaBit(mesaj, poz);
//System.out.println("Mesaj primit eronat: " + mesajgresit);
System.out.println();
}

当我尝试将函数的值分配给 P 时,它告诉我 .class 是预期的。我做错了什么?

最佳答案

您似乎犯了拼写错误。应该是下面的 int[] P = new int[n];

关于java - 将一个数组分配给另一个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22621702/

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