Nicolas Mustaro
Nicolas Mustaro

Reputation: 681

ArrayList of values not being generated... code-specific, java/android

Ok, I have this program that takes input of single digits 0-9. It then calculates how many times each digit occurs as compared to the total number of digits entered, and stores how many times each digit occured in the array of timesOccured[]. The value is the times the number occured, the index is the number, so if timesOccured[1] is == 15, 1 occured 15 times.

I have an ArrayList called leastCommonNumbers, which is a list of 4 of the least common numbers occured. Then, i have an ArrayList called recommendedNumbers that is the four possible combinations of three out of the four leastCommonNumbers.

Everything here is working fine except the ArrayList recommendedNumbers is not being generated... It has to be some kind of logical flaw but I can't figure out why it isn't working... Here's the declarations:

List<Integer> leastCommonNumbers = new ArrayList();
List<String> recommendedNumbers = new ArrayList();
double timesOccured[]={0,0,0,0,0,0,0,0,0,0}

Here's the code:

double[] nums = timesOccured;
        double temp;
        int temp2;
        leastCommonNumbers.clear();
        recommendedNumbers.clear();

        for(int al = 0; al<nums.length;al++){
            for(int al2 = 0;al2<nums.length-1;al2++){
                if(nums[al2] > nums[al2+1]){
                    temp = nums[al2];
                    nums[al2]=nums[al2+1];
                    nums[al2+1]=temp;
                }}}
        for(int b = 0; b ==3;b++){
            for(int r = 0; r<nums.length; r++){
            if(nums[b] == timesOccured[r]){
                leastCommonNumbers.add(r);
            }}}


        for(int y = 0; y == 3; y++){
            int t = 0;
            recommendedNumbers.add(String.valueOf(leastCommonNumbers.get(t))+String.valueOf(leastCommonNumbers.get(t+1))+String.valueOf(leastCommonNumbers.get(t+2)));
            temp2 = leastCommonNumbers.get(0);
            for(int a = 0; a == 3; a++){
                if(a < 3){

                    leastCommonNumbers.set(a, leastCommonNumbers.get(a+1));
                }else{
                    leastCommonNumbers.set(a, temp2);
                }}}

timesOccured is initlialized to all 0's, and is changed throughout the operation of the program. When I try to use recommendedNumbers after running this I get an error that the size of recommendedNumbers is 0, i.e. has no values.

So confused...

Upvotes: 1

Views: 77

Answers (1)

Dalmas
Dalmas

Reputation: 26547

The condition of your for loops is always false :

for(int b = 0; b == 3;b++){
...
for(int y = 0; y == 3; y++){

So the loops never gets executed. I guess you wanted to use <= instead :

for(int b = 0; b <= 3;b++){
...
for(int y = 0; y <= 3; y++){

Upvotes: 2

Related Questions