ok so the program gets a list of numbers, and it counts how many times a number is entered.

for(int i = 0; i < numList.size(); i++){
		for(int j = numList.size() - 1; j > i; j--){
			if(numList.get(i) == numList.get(j)){
				count++;
				numList.remove(j);
				
			}
		}
		System.out.println(numList.get(i) +"  " + count);
		count = 1;
	}

this works except if i were to enter a number that's 100 or greater, it doesn't work which is weird.

for example, if i entered: 23, 23, 5, 3.
it would output:
23 2
5 1
3 1
this is correct

this doesn't work if i were to enter 100 or 500 or anything greater than 100.
input: 500, 500, 2, 5.
output:
500 1
500 1
2 1
5 1

Edited 5 Years Ago by plasticfood: n/a

ArrayList <Integer> numList = new ArrayList <Integer>();
	
	int num = 0;
	
	while(num != -999){
		System.out.println("enter a series of numbers or typed -999 to stop: ");
		num = kb.nextInt();
		if(num == -999){
			break;
		}
		numList.add(num);
	}

thanks for helping me out...

Edited 5 Years Ago by plasticfood: n/a

if(numList.get(i) == numList.get(j))

You are actually comparing if two Integer objects are referencing the same object. Try numList.get(i).intValue() == numList.get(j).intValue()

Couldn't say for sure why the way you are doing it works in some cases.

thanks!! that works!!!

also the equals method works too.

Edited 5 Years Ago by plasticfood: n/a

This question has already been answered. Start a new discussion instead.