{ "question_id": 7436836, "question_title": "数组元素统计", "question_content": "
定义一个长度为5的数组arr1,用于存放5个1~9的随机整数(范围包含1和9),再定义一个长度为2的数组arr2,统计arr1中的元素对2求余等于0的个数,保存到arr2[0], 统计arr1中的元素对3求余等于0的个数,保存到arr2[1],在控制台打印输出arr2的所有元素
", "difficulty": "简单", "answer_id": 53409011, "answer_content": "\npackage com.auskat.demo.cc;\n\nimport java.util.Random;\n\n/**\n * 类文件: RandomTest\n * <p>\n * <p>\n * 类描述:\n * <p>\n * 作 者: AusKa_T\n * <p>\n * 日 期: 2021/5/27 0027\n * <p>\n * 时 间: 13:29\n * <p>\n */\npublic class RandomTest {\n\n public static void main(String[] args) {\n\n int arr1[] = new int[5];\n for (int i = 0; i < arr1.length; i++) {\n arr1[i] = new Random().nextInt(9) + 1;\n }\n\n\n int i2 = 0;\n int j3 = 0;\n for (int i = 0; i < arr1.length; i++) {\n if(arr1[i] % 2 == 0) {\n i2++;\n }\n if(arr1[i] % 3 == 0) {\n j3++;\n }\n }\n\n int arr2[] = new int[2];\n arr2[0] = i2;\n arr2[1] = j3;\n\n for (int i = 0; i < arr2.length; i++) {\n System.out.println(arr2[i]);\n }\n\n }\n}\n
\n\n\n", "tag_name": "java", "java": "package com.auskat.demo.cc;\nimport java.util.Random;\npublic class RandomTest {\n\tpublic static void main(String[] args) {\n\t\tint arr1[] = new int[5];\n\t\tfor (int i = 0; i < arr1.length; i++) {\n\t\t\tarr1[i] = new Random().nextInt(9) + 1;\n\t\t}\n\t\tint i2 = 0;\n\t\tint j3 = 0;\n\t\tfor (int i = 0; i < arr1.length; i++) {\n\t\t\tif (arr1[i] % 2 == 0) {\n\t\t\t\ti2++;\n\t\t\t}\n\t\t\tif (arr1[i] % 3 == 0) {\n\t\t\t\tj3++;\n\t\t\t}\n\t\t}\n\t\tint arr2[] = new int[2];\n\t\tarr2[0] = i2;\n\t\tarr2[1] = j3;\n\t\tfor (int i = 0; i < arr2.length; i++) {\n\t\t\tSystem.out.println(arr2[i]);\n\t\t}\n\t}\n}", "topic_link": "https://bbs.csdn.net/topics/600469875", "status": 1, "keywords": "算法初阶,基础知识,随机算法,概率分析和随机算法", "license": "csdn.net", "notebook": { "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/22.ipynb?type=file" }, "notebook_enable": 1 }