gpt4 book ai didi

java - java中的“.class错误”

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

您好,我对编码非常陌生,当我尝试运行下面的代码时,我不断收到“.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 类。做一次就够了

关于java - java中的“.class错误”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39881673/

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