生活随笔
收集整理的這篇文章主要介紹了
投票统计,遍历数据
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Scanner in
=new Scanner(System
.in
);int x
;int[] numbers
=new int[10];x
=in
.nextInt();while(x
!=-1){if(x
>=0&&x
<10){numbers
[x
]++;}x
=in
.nextInt();}for(int i
=0;i
<numbers
.length
;i
++){System
.out
.println(i
+";"+numbers
[i
]);}
復制數組
Scanner in
=new Scanner(System
.in
);int[] data
= {1,2,3,4,5,55,999,65,41,22};int x
=in
.nextInt();int loc
=-1;boolean found
=false;for(int i
=0;i
<data
.length
;i
++){if(x
==data
[i
]){loc
=i
;break;}}for(int k
:data
){if(k
==x
){found
=true;break;}}if(found
){System
.out
.println(x
+"在其中");}else{System
.out
.println(x
+"不在其中");}if(loc
>-1){System
.out
.println(x
+"是第"+(loc
+1)+"個");}else{System
.out
.println(x
+"不在其中");}
總結
以上是生活随笔為你收集整理的投票统计,遍历数据的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。