【问题标题】:About .length property for int关于 int 的 .length 属性
【发布时间】:2015-12-12 16:20:39
【问题描述】:

所以我正在研究用于将分数转换为成绩的代码,我对以下步骤有点困惑:

public static String score2grade(int score){
  int [] bottoms = {95, 90, 85, 80};
  String [] grade = {A+, A, A-, B+};
  for(int i = 1; i < bottoms.length; i++){
     if (score >= bottoms[i]) return grade[i];

我不太了解int i = 1; i &lt; bottoms.length; i++ 部分,所以我在这里基本上是什么? bottoms 的长度属性是什么?

【问题讨论】:

标签: java


【解决方案1】:

在 Java 中,length 属性表示您在数组 bottoms[] 中使用的最大元素数。这里bottoms[]数组的长度是3。因为在'0'处元素95存在。在'1'位置存在元素90。并且在'2'位置存在元素85。并且在'3'位置元素80存在。

部分代码用于迭代。基本上它说从一开始计数。并在第一个循环中将 i 的值增加 1。并继续执行此过程,直到 i 的值小于底部数组的长度。当它相等时,循环就会中断。

【讨论】:

    猜你喜欢
    • 2010-10-11
    • 1970-01-01
    • 1970-01-01
    • 2017-12-29
    • 1970-01-01
    • 2021-02-10
    • 2022-01-06
    • 2021-04-25
    • 1970-01-01
    相关资源
    最近更新 更多