嗨,我是编码的超级新手,尝试运行下面的代码时,我总是收到'.class'错误。我想念什么?

import java.util.Scanner;

import java.util.Scanner;


public class PeopleWeights {
    public static void main(String[] args) {
        Scanner scnr = new Scanner (System.in);
        userWeight = new int[5];
        int i = 0;

        userWeight[0] = 0;
        userWeight[1] = 5;
        userWeight[2] = 6;
        userWeight[3] = 7;
        userWeight[4] = 9;

        System.out.println("Enter weight 1: ");
        userWeight = scnr.nextInt[];

        return;
    }
}

最佳答案

这就是问题

userWeight = scnr.nextInt[];


解决方法:

userWeight[0] = scnr.nextInt();        //If you intended to change the first weight


要么

userWeight[1] = scnr.nextInt();        //If you intended to change the value of userWeight at index 1 (ie. the second userWeight)


应该管用

PS:为预防起见,请勿两次导入Scanner类。这样做一次就足够了

08-28 15:59