I want to create a program that counts the number of occurrence of integers from user input e.g. 121221315
0: 0 times
1: 4 times
2: 3 times
3: 1 times
4: 0 times... etc up until 9...
But my code reads e.g. 121221315 as a single integer and i need to find a way that can split each integers
Another issue is that I don't know how to stop the first for loop... I have no clue which condition to put in on how to stop the loop when the program finished reading the input... I have just started learning coding.. please help me with simple/easy codes!!
I have following code
import java.util.Scanner;
public class Occurrence {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] number = new int[100];
System.out.print("Enter the integers between 1 and 100: ");
for (int i = 0; i < number.length; i++) {
int a = input.nextInt();
number[a] += a;
break;
}
for (int i = 1; i < number.length; i++) {
if (number[i] != 0) {
if (number[i] / i > 1)
System.out.println(i + " occurs " + number[i] / i + " times");
else
System.out.println(i + " occurs " + number[i] / i + " time"); }
}
}
}