So I'm trying to count the number of integer occurrences in this program. The code still doesn't work, but am I on the right track?
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int userInput = 0;
ArrayList<Integer> myList = new ArrayList<Integer>();
int[] newArray = new int[myList.size()];
int index1 = -1;
int current;
for (int num = 0; num <= userInput ; num++)
{
System.out.println("Please enter a random number between 0 and 50, enter a negative number to end input: ");
num--;
if(userInput >= 0 || userInput <= 50)
{
userInput++;
userInput = scan.nextInt();
index1++;
myList.add(userInput);
}
if (userInput < 0 || userInput > 50)
{
myList.remove(index1);
index1--;
break;
}
}
for (int num2 = 0; num2 < myList.size(); num2++)
{
current = myList.get(num2);
if(current == myList.get(num2))
{
newArray[current-myList.get(num2)]++;
}
}
for (int number=0; number < newArray.length; number++)
{
System.out.println(number + "1");
System.out.println(" : " + newArray[number]);
}
}
}
edit: just wanted to add that I can run the program, but when I input an integer that is out of bounds (not between 0 and 50), I get an error