123456789101112131415161718192021222324252627282930313233 |
- package com.loveCoding.homework.j20250517_method;
- import java.util.Scanner;
- /**
- * @author WanJl
- * @version 1.0
- * @title T3
- * @description
- * **3. 元素查找器**
- * 要求:输入一个数字,判断它是否存在于数组中,并统计出现次数
- * 示例输入:数组`{2,5,3,2,8,2}`,查找数字2
- * 示例输出:存在,出现3次
- * @create 2025/5/24
- */
- public class T3 {
- public static void main(String[] args) {
- Scanner sc=new Scanner(System.in);
- int[] arr={2,5,3,2,8,2};
- int count=0;
- int n=sc.nextInt();
- for (int i = 0; i < arr.length; i++) {
- if (n==arr[i]){
- count++;
- }
- }
- if (count>0){
- System.out.println("存在,出现"+count+"次");
- }else {
- System.out.println("不存在");
- }
- }
- }
|