Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


sum of multiples filter_list
Author
Message
sum of multiples #1
Find the sum of the multiples of 5 or 7 under 851

i know it's easy but i didn't sleep well yesterday and i'm eally not focued can't figure out what im doing wrong here here's my code help appreciated pls !!

Spoiler:
Code:
public static void main(String[] args) {
        int sum1 = 0, sum2 = 0;
        int i = 0;
        int i1 = 0;
        do {
            i = i + 5;
        } while (i < 851);

        System.out.println(i);

        do {
            i1 = i1 + 7;
        } while (i1 < 851);

        System.out.println(i1);
        i += i1;
        System.out.println("solution = " + i);
    }
}
[Image: blackeagle_zps6ad86521.gif]

Reply

sum of multiples #2
Find the sum of the multiples of 5 or 7 under 851

i know it's easy but i didn't sleep well yesterday and i'm eally not focued can't figure out what im doing wrong here here's my code help appreciated pls !!

Spoiler:
Code:
public static void main(String[] args) {
        int sum1 = 0, sum2 = 0;
        int i = 0;
        int i1 = 0;
        do {
            i = i + 5;
        } while (i < 851);

        System.out.println(i);

        do {
            i1 = i1 + 7;
        } while (i1 < 851);

        System.out.println(i1);
        i += i1;
        System.out.println("solution = " + i);
    }
}
[Image: blackeagle_zps6ad86521.gif]

Reply

RE: sum of multiples #3
You're not tracking the sum anywhere? You are looking over the multiples of 5 and 7 with the i += 5 and i +=7 but the sum isn't being stored. You should do something like

Code:
do {
    i = i + 5;
    sum += i //add i to sum
} while (i < 851);

similar code for the multiples of 7

Reply

RE: sum of multiples #4
You're not tracking the sum anywhere? You are looking over the multiples of 5 and 7 with the i += 5 and i +=7 but the sum isn't being stored. You should do something like

Code:
do {
    i = i + 5;
    sum += i //add i to sum
} while (i < 851);

similar code for the multiples of 7

Reply

RE: sum of multiples #5
omg i feel like an idiot now :/ thx for the help @"dropzon3"
[Image: blackeagle_zps6ad86521.gif]

Reply

RE: sum of multiples #6
omg i feel like an idiot now :/ thx for the help @"dropzon3"
[Image: blackeagle_zps6ad86521.gif]

Reply







Users browsing this thread: 1 Guest(s)