簡體   English   中英

我需要在這里導入一些東西嗎?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM