[英]Do I need to import something here?
我是 Java 的初学者,我正在创建一个程序,在接受用户 30 次输入后,将学生的姓名和权重存储在两个不同的数组中。 这是我的代码:
import java.util.Scanner;
public class bodymass {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
String[] studentName= new String[30];
System.out.println("Please enter the Names of 30 students");
// This "i" is your counter.
for (int i=0; i< studentName.length; i++) {
studentName[i]= scan.nextLine();}
System.out.println("Please enter the Weight of 30 students");
Scanner scan1= new Scanner(System.in);
int[] studentWeight= new int[30];
for(int i=0; i<studentWeight.length; i++) {
studentWeight[i]= scan.nextInt();}
}
}
但是,当我调试它时,我收到消息:
线程“main”中的异常 java.lang.Error:未解决的编译问题:在 bodymass.main(bodymass.java:5)
这是什么意思? 如果有人指导我完成此操作,我将不胜感激。
我已经为 2 个学生尝试过,并确保您的 java 课程没有错误。
package com.test.practice;
import java.util.Scanner;
public class Bodymass {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
String[] studentName= new String[2];
System.out.println("Please enter the Names of 2 students");
// This "i" is your counter.
for (int i=0; i< studentName.length; i++) {
System.out.print("Enter the student name at postion "+i+". ");
studentName[i]= scan.nextLine();
}
System.out.println("Please enter the Weight of 2 students");
Scanner scan1= new Scanner(System.in);
int[] studentWeight= new int[2];
for(int i=0; i<studentWeight.length; i++) {
System.out.print("weight of student at position "+i+" ");
studentWeight[i]= scan.nextInt();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.