且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java 中带参带返回值方法的使用

更新时间:2022-09-18 23:04:47

public class mains {

public static void main(String[] args) {

mains hello = new mains();

int[] scores={79,52,98,81};

        hello.sort(scores);

        System.out.println("第一"+hello.sort(scores));

//调用方法,传入成绩数组,并获取成绩的个数

//int count= hello.sort(scores);

       // System.out.println(hello.sort(scores));

//System.out.println("共有"+count+"个成绩信息!");

}

    

/*

 * 功能:将考试成绩排序并输出,返回成绩的个数

 * 定义一个包含整型数组参数的方法,传入成绩数组

 * 使用Arrays类对成绩数组进行排序并输出

 * 方法执行后返回数组中元素的个数

 */

public int sort(int scores[]){

Arrays.sort(scores);

System.out.println("第二"+Arrays.toString(scores));

        //返回数组中元素的个数

        return 1;

}

}

本文转自12691034博客51CTO博客,原文链接http://blog.51cto.com/12701034/1932887如需转载请自行联系原作者


笑容掩饰爱