1

当我编译以下代码时,它会显示此错误:main(java.lang.String) already declared in main(String args[])

public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int[] array1 = new int[10];
    for (int i = 0; i < array1.length; i++)
        if (sc.hasNextInt())
            array1[i] = sc.nextInt();
    sc.close();
    int[] array2 = new int[10];
    for (int i = 0; i < array2.length; i++)
        if (sc.hasNextInt())
            array2[i] = sc.nextInt();
    median(array1, array2);
    sc.close();
}
4

1 回答 1

0

您正在“已经声明”,因为您有两次以下代码行......

for (int i = 0; i < array1.length; i++)

for (int i = 0; i < array1.length; i++)

如果你想按原样使用你的代码,你需要大括号......

for (int i = 0; i < array1.length; i++){ //some code }

for (int i = 0; i < array2.length; i++){ //some code }

于 2013-04-12T15:32:11.273 回答