dimanche 22 juillet 2018

Why am I getting output It's a number: 999997

Task: Print the largest 7-digit number that is not divisible by 3 and is divisible by 7

This is my code

    for (int i = 1000000; i < 10000000; i--) {
        if (i % 7 == 0 && i % 3 != 0) {
            System.out.println("It's a number: " + i);
            break;
        }
    }

Output:

It's a number: 999997

Why am I getting 6-digit number? What's wrong if I put in for the loop from the 7-digit to the 8-digit?

Aucun commentaire:

Enregistrer un commentaire