dimanche 5 mars 2017

Method for returning even numbers

This method will not compile, can't see why. Error is:"can't find symbol-variable i". The int i is defined in the for-loop. The method should return the even numbers between int a and int b.

The code:

public int partall(int a, int b){
        int partall;
        int største; 
        int minste;
        if(a == b){
            partall = 0;
        }else {
            if(a>b) {
            største = a;
            minste = b; 
        } else if(a<b) {
            minste = a;
            største = b;

        for(int i = minste;  i<= største; i++){
            if(i % 2 == 0) {
                partall = i;
            }
        }

       }

    }
    return i;
}

Aucun commentaire:

Enregistrer un commentaire