请问实参可以这样传入吗

import java.util.Arrays;
public class HelloWorld {
    public static void main(String[] args) {
        HelloWorld hello = new HelloWorld();
        //调用方法,传入成绩数组,并获取成绩的个数
        int count=hello.sort(int scores={79,52,98,81});
        System.out.println("共有"+count+"个成绩信息!");
    }
    /*
     * 功能:将考试成绩排序并输出,返回成绩的个数
     * 定义一个包含整型数组参数的方法,传入成绩数组
     * 使用Arrays类对成绩数组进行排序并输出
     * 方法执行后返回数组中元素的个数
     */
    public int sort(int[] scores           ){
        Arrays.sort(scores);
        System.out.println(Arrays.toString(scores));
        //返回数组中元素的个数
        return scores.length;
    }
}

加粗斜体的那一行是不是不能这么写


慕数据6005589
浏览 1116回答 2
2回答

暹罗罗罗罗罗罗

是的,不可以这么写。在外面定义个int类型的数组。然后传进去。你这个粗体的数组也写错了

慕数据6005589

请问数组哪里写错了呢

慕瓜9220888

QVLBQUAEVVTSEOYPTLMPILQEDKNDJESQDPUNRGXCTNPFNHXZEKVZMARKESCPJNELNTKQNRLTQHYCPBFCQWYUBRVFMNVBKENHSMJCBONAQEIWHQOHDXBVMRNCJYMWAYBAMWLHIMZAMWZZGAKIZVRNNROFONZMSSMJNNTBXNWUYCRWLBAQDHPCCUKAYFFTNHPCIORLTDACYHETREIAPFYERVJHWTUTEHRXXSFDTHTTLSVRDSAAOHXMXGSGPADCZVPJSDSGREAQWCWTEREAZFLPMGABGWGGGSWUCHNGURSFDLWMSSMZXUWDJCIMTNBQCKJFTDHVYUTPPBPMGWODJSJTPWGSYXNHBPMOGCRXYCPNEQCOLISQHNCJZOPJDHEQWFVZJAHUMIBBYCMRGPOEURLZNTLBNTNPTHMEYNXPTNKIHHKNWZDBKCXYJLAJSROOICHMBQQIAKKNGEHKXRLZONDIJTQOVUUGQFZRCYPTNZQUPOSXHFNMHLVWKQPDERZHMJMTWDKYFHHJCDLGKMIEURAQYWCKUYJZUTPASOEVMQDILGPLLORKRRMAAEWKZCSQUOCPKPLBKYIMQVFOLHBBFJXMYUKECMGPEUKW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