samedi 29 mai 2021

Array: if all 4 Elements included count up

My code isn't working right. Could someone help me out? Everytime there is one of those items: (socken,schuhe, hose, pullover) in the array (doesn‘t matter where) then it should count 1 up. It shouldn‘t count how many times each of them is included in total, just if all of them are included once and then again if all 4 are in the array etc. and then the total number of them. If I use && I get 0 and if I use || in the if statement I get 16. I should get 3 instead of 16 though. I would be really happy if someone could help me out.

    int HOSE = 1;
    int PULLOVER = 2;
    int SOCKEN = 3;
    int MÜTZE = 4;
    int SCHUHE = 5;
    int TANKTOP = 6;
    int LONGSLEEVE = 7;
    int KLEID = 8;
    int BLUEJEANS = 9;
    int BOOTIES = 10;
    int WEDGES = 11;
    int HIGHHEELS = 12;
    int KAROHEMD = 13;
    int BLAZER = 14;
    int HALSTUCH = 15;

    int[] lager = { HOSE, SCHUHE, SOCKEN, PULLOVER, PULLOVER, HOSE, HALSTUCH, MÜTZE, SCHUHE, TANKTOP, LONGSLEEVE,
            PULLOVER, PULLOVER, KLEID, KLEID, BLUEJEANS, HOSE, SOCKEN, SCHUHE, BOOTIES, WEDGES, HIGHHEELS, KAROHEMD,
            BLAZER, SCHUHE, HALSTUCH, SOCKEN, HOSE, PULLOVER };

    int counter = 0;
    for (int i = 0; i < lager.length; i++) {
        if (lager[i] == SCHUHE || lager[i] == SOCKEN || lager[i] == HOSE || lager[i] == PULLOVER) {
            counter++;
            break;
        
        }
    }

    System.out.println(counter);

Aucun commentaire:

Enregistrer un commentaire