import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] nums = new int[n]; for (int i = 0; i < n; i++) { nums[i] = in.nextInt(); } int num = in.nextInt(); int count = 0; for (int i = 0; i < n; i++) { if (num == nums[i]) { count++; } } System.out.println(count); } }
import java.util.Scanner; import java.util.ArrayList; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNextInt()) { // 注意 while 处理多个 case int a = in.nextInt(); ArrayList<Integer> list =new ArrayList<>(); for(int i=0;i<a;i++) { list.add(in.nextInt()); } int b =in.nextInt(); System.out.println(list.stream().filter(x -> x==b ).count()); } } }
import java.util.HashMap; import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String nums = sc.nextLine(); String s = sc.nextLine(); String aimstr = sc.nextLine(); HashMap<String,Integer> map=new HashMap<>(); String[] split = s.split(" "); for (int i = 0; i < split.length; i++) { String s1 = split[i]; if (map.containsKey(s1)){ //存在 Integer count = map.get(s1); count++; map.put(s1,count); }else { //不存在 map.put(s1,1); } } if (map.get(aimstr)!=null){ System.out.println(map.get(aimstr)); }else { System.out.println("0"); } } }
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int a=in.nextInt(); int[] arr=new int[a]; for(int i=0;i<a;i++){ arr[i]=in.nextInt(); } int b=in.nextInt(); int count=0; for(int i=0;i<arr.length;i++){ if(arr[i]==b){ count++; } } System.out.print(count); } }
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int all=sc.nextInt(); int[] arr=new int[all]; for(int i=0;i<all;i++) arr[i]=sc.nextInt(); int flag=sc.nextInt(); int count=0; for(int i:arr) if(i==flag) count++; System.out.print(count); } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } int x = sc.nextInt(); int count = 0; for (int a : arr) { if (a == x) { count++; } } System.out.print(count); } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while(scanner.hasNext()){ int n = scanner.nextInt(); //要输入数据的集合 List<Integer> inputList = new ArrayList<>(); //计数,出现所找数字就+1 int toCountNumTimes = 0; //输入 for(int i = 0;i < n;i++){ inputList.add(scanner.nextInt()); } //整数x int x = scanner.nextInt(); for(int j = 0; j < inputList.size();j++){ if(inputList.get(j) == x){ toCountNumTimes++; } } System.out.println(toCountNumTimes); } } }
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int count = scanner.nextInt(); if (count < 1 || count > 100) { return; } List<Integer> list = new ArrayList<>(count); for (int i = 0; i < count; i++) { list.add(scanner.nextInt()); } int number = scanner.nextInt(); int total= (int) list.stream().filter(item -> number == item).count(); System.out.println(total); } }
import java.util.Scanner; public class Main { public static void main(String args[]){ Scanner s= new Scanner(System.in); int n=s.nextInt(); int a[]=new int [n]; while(--n>=0) a[n]=s.nextInt(); int x=s.nextInt(),count=0; for(int i:a) { if(i==x) count++; } System.out.println(count); } }
import java.util.ArrayList; import java.util.Scanner; public class Main{ public static void main(String[] args) { ArrayList<Integer> list = new ArrayList<>(); Scanner sc = new Scanner(System.in); //输入需要输入数字个总个数 int n = sc.nextInt(); for (int i = 0; i < n; i++) { list.add(sc.nextInt()); } // 输入查询的数字 int m = sc.nextInt(); for (int index = 0; index < list.size(); ) { if(m != list.get(index)){ //判断集合里面有没有相同的数字,如果有删除,索引不增加。 list.remove(list.get(index)); }else{ //不相同的不删除,索引增加 index++; } } //打印输出集合的长度 System.out.println(list.size()); } }
import java.util.*; public class Main { public static void main(String [] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextInt()) { int n=sc.nextInt(); int [] arr=new int[n]; for(int i=0;i<n;i++) { int a=sc.nextInt(); arr[i]=a; } int target=sc.nextInt(); int count=0; for(int i=0;i<arr.length;i++) { if(arr[i]==target) { count++; } } System.out.println(count); } } }