很菜的问题,求指教!

wsq360525224 2011-05-18 02:37:11
定义数组X,怎么表示X的长度?
...全文
84 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
爱的世界999 2011-05-18
  • 打赏
  • 举报
回复
byte[] phone =new byte[81]; //建立一个byte类型的数组,长度为81
phone[i]!=0中phone[i]! //数组的第i的位置不等0

如:

byte[] phone =new byte[81]; //建立一个byte类型的数组,长度为81
phone[1]!=0中phone[1]! //数组第二个取值不等于0

同时给楼主举个例子:

public class StudyArrary {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
byte[] phone =new byte[81]; //建立一个byte类型的数组,长度为81
for(int a = 0; a < 81; a++)
phone[a]=(byte)a; //数组的第i的位置不等0

for(int i = 0; i < 81; i++){
if (phone[i]!=0) {
System.out.println("phone["+i+"]不等于0"+",phone"+i+"是"+phone[i]);
}
else
System.out.println("phone["+i+"]等于0"+",phone"+i+"是"+phone[i]);
}
}

}
winnerway 2011-05-18
  • 打赏
  • 举报
回复
x.length,楼主给分。。
rockay2006 2011-05-18
  • 打赏
  • 举报
回复
x.lenth;
扁鵲東南飛 2011-05-18
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 x19881216 的回复:]
int[] arr = new int[5]; or int[] arr = {0,1,2,3,4,5}; or int[] arr = new int[]{0,1,2,3,4,5};

arr.length //5
[/Quote]
很明确了。
小二郎 2011-05-18
  • 打赏
  • 举报
回复
x.length()
wsq360525224 2011-05-18
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 xiang123yan 的回复:]
X.length
[/Quote]

哦哦。。想通了。谢谢,数组有length属性,不是方法。
艾弗森 2011-05-18
  • 打赏
  • 举报
回复
小绵羊 2011-05-18
  • 打赏
  • 举报
回复
int[] arr = new int[5]; or int[] arr = {0,1,2,3,4,5}; or int[] arr = new int[]{0,1,2,3,4,5};

arr.length //5
xiang123yan 2011-05-18
  • 打赏
  • 举报
回复
X.length
zqs0605 2011-05-18
  • 打赏
  • 举报
回复
X.length

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧