• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

int count=hello.sort(scores); 这段代码怎么理解

int count=hello.sort(scores);  这段代码怎么理解
能不能写成int count=scores.lenght;  
附上源代码。


import java.util.Arrays;




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

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

全部参与1

int count=hello.sort(scores);
调用的是底下的sort方法,该sort方法对数组排序并返回了scores.lenght;
public int sort( int[] scores ){
Arrays.sort(scores);//排序
System.out.println(Arrays.toString(scores));

//返回数组中元素的个数
return scores.lenght; //返回长度

}
}
如果你只想知道数组长度那当然可以直接写成int count=scores.lenght; 但是你不是还有实现排序么

使用道具 举报

发新帖

发布任务需求已有1031166位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!