在JAVA中为字符串分配字符串。我哪里做错了?

时间:2014-11-26 22:00:00

标签: java arrays string

在我的代码中:

import java.util.Scanner;
    public class HighestTwo {
        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            String[] s = new String[5];
            int[] g = new int[5];

            for(int i=0; i<=4; i++) {
                System.out.println("Enter the " + (i+1) + ". student`s name:");
                s[i] = input.nextLine();
                System.out.println("Enter the " + (i+1) + ". student`s grade:");
                g[i] = input.nextInt();
            }
        }
    }
}

输入第一个名字和成绩后,它会直接跳到成绩输入并忽略第二个和第三个上的字符串,依此类推。

我看不出为什么会这样。我该如何解决这个问题?

0 个答案:

没有答案