mercredi 18 décembre 2019

How to find even numbers then add them - JAVA

I have coded this

int A = 69;
do {
    A /= 2;
    if (A % 2 == 0) {
        System.out.println(A);
    }
} while (A != 1);

Output:

34
8
4
2

How to sum output? In order to be:

34 + 8 + 4 + 2 = 48

Aucun commentaire:

Enregistrer un commentaire