Sinisterly
sum of multiples - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: Java, JVM, & JRE (https://sinister.li/Forum-Java-JVM-JRE)
+--- Thread: sum of multiples (/Thread-sum-of-multiples)



sum of multiples - blackeagle - 09-22-2014

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); } }



sum of multiples - blackeagle - 09-22-2014

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); } }



RE: sum of multiples - dropzon3 - 09-22-2014

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


RE: sum of multiples - dropzon3 - 09-22-2014

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


RE: sum of multiples - blackeagle - 09-22-2014

omg i feel like an idiot now :/ thx for the help @dropzon3


RE: sum of multiples - blackeagle - 09-22-2014

omg i feel like an idiot now :/ thx for the help @dropzon3