
import java.io.*; class count_no { public static void main(String args[]) { try { int [] size=new int[9]; int i,temp=0; DataInputStream dis=new DataInputStream(System.in);
for(i=0;i<9;i++)
{
int no=Integer.parseInt(dis.readLine());
if(no==1)
{
temp++;
}
else if(no==2)
{
temp++;
}
}System.out.println(temp);
}catch(Exception e){}
}
}

thanks

Here is a java example that accepts 9 integers from the user and count the occurrence of each integer.
import java.util.*;
public class CountNumberFrequency {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] arr = new int[9];
System.out.println("Enter numbers:");
for (int i = 0; i < arr.length; i++) {
arr[i] = input.nextInt();
}
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for (int i = 0; i < arr.length; i++) {
int key = arr[i];
if (map.containsKey(key)) {
int occurrence = map.get(key);
occurrence++;
map.put(key, occurrence);
} else {
map.put(key, 1);
}
}
Iterator iterator = map.keySet().iterator();
while (iterator.hasNext()) {
int key = (Integer) iterator.next();
int occurrence = map.get(key);
System.out.println(key + " : " + occurrence + " times.");
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.