小编Li4*_*ick的帖子

Intellij将所有方法标记为未使用,即使它们已被使用

这是代码的一部分.

public class MyPolynomial {

    private double coeffs[];
    private int degree;

    public MyPolynomial(double ... coeffs) {
        if (coeffs != null && coeffs.length > 0) {
            this.coeffs = new double[coeffs.length];
            System.arraycopy(coeffs, 0, this.coeffs, 0, coeffs.length);
        }
    //this.coeffs = Arrays.copyOf(coeffs, coeffs.length);
    }

    public MyPolynomial(String filename) {
        Scanner in = null;
        try {
            in = new Scanner(new File(filename));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        this.degree = in.nextInt();
        coeffs = new double[degree+1];
        for (int i = 0; i < coeffs.length; i++) {
            coeffs[i] …
Run Code Online (Sandbox Code Playgroud)

java intellij-idea

5
推荐指数
1
解决办法
1863
查看次数

C fscanf向数组添加元素,不应该

#include <stdio.h>


int main() {

    FILE *input;
    FILE *output;

    input = fopen("algsort.in", "r");
    output = fopen("algsort.out", "w");

    int n = 0;
    fscanf(input, "%d", &n);        // reads n = 7

    int i;
    int a[6] = {1, -1, 0, 33, 6, 5};


    for(i = 0; i < 8; i++) {     // 8 is on purpuse
        printf("%d  ", a[i]);    // the output is [1 -1 0 33 6 5 7 $(Random location in memory)]
    }


    return 0;
}
Run Code Online (Sandbox Code Playgroud)

fscanf在数组末尾附加一个元素.这是一个问题,因为它干扰了排序算法,遗漏了一个大于n的元素.我知道for循环的限制,问题是,"n"元素仍然是数组的一部分.问题:7来自哪里?

c

2
推荐指数
1
解决办法
44
查看次数

标签 统计

c ×1

intellij-idea ×1

java ×1