首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2ME开发 >

编写一个整数数组,为数组赋值,统计其中正整数个数,该怎么解决

2012-03-30 
编写一个整数数组,为数组赋值,统计其中正整数个数编写一个整数数组,为数组赋值,统计其中正整数个数,用java

编写一个整数数组,为数组赋值,统计其中正整数个数
编写一个整数数组,为数组赋值,统计其中正整数个数,用java写,谢谢

[解决办法]

Java code
public class GetCount {    /**     * @param args     */    public static void main(String[] args) {        //这里以随便生成的数来判断正整数的个数        int[] arr = new int[6];        Random r = new Random();        int count = 0;//统计正整数个数        System.out.print("数组中的数为:");        for(int i=0; i<6; i++) {            arr[i] = r.nextInt();//给数组赋值            System.out.print(arr[i] + "   ");        }                //计算正正数的个数        for(int i=0; i<6; i++) {            if(arr[i]>0)                count++;        }        System.out.println();        System.out.println("正整数的个数为:" + count);    }} 

热点排行