Here is what I am trying to do
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
Here are my 3 different sets of code, the first 2 I know are definatly wrong, and I am just wondering how i would change them to be correct, but the third one I dont understand why it is wrong
public class Main { private static String result; public static void main( String argv[] ) { int count = 7; if (count % 1 == 0 && count % 2 == 0 && count % 3 == 0 && count % 4 == 0 && count % 5 == 0 && count % 6 == 0 && count % 7 == 0 && count % 8 == 0 && count % 9 == 0 && count % 10 == 0 && count % 11 == 0 && count % 12 == 0 && count % 13 == 0 && count % 14 == 0 && count % 15 == 0 && count % 16 == 0 && count % 17 == 0 && count % 18 == 0 && count % 19 == 0 && count % 20 == 0){ System.out.println("result" + result); } else { System.out.println("wrong"); int++; } } }
public class Main { private static String result; public static void main( String argv[] ) { int count = 7; inner : count++; if (count % 1 == 0 && count % 2 == 0 && count % 3 == 0 && count % 4 == 0 && count % 5 == 0 && count % 6 == 0 && count % 7 == 0 && count % 8 == 0 && count % 9 == 0 && count % 10 == 0 && count % 11 == 0 && count % 12 == 0 && count % 13 == 0 && count % 14 == 0 && count % 15 == 0 && count % 16 == 0 && count % 17 == 0 && count % 18 == 0 && count % 19 == 0 && count % 20 == 0){ System.out.println("result" + result); } else { count++; continue inner; } } }
public class Main { public static void main(String[] args) { System.out.println("Calcluate this mofo"); for (int count = 1; count % 1 == 0 && count % 2 == 0 && count % 3 == 0 && count % 4 == 0 && count % 5 == 0 && count % 6 == 0 && count % 7 == 0 && count % 8 == 0 && count % 9 == 0 && count % 10 == 0 && count % 11 == 0 && count % 12 == 0 && count % 13 == 0 && count % 14 == 0 && count % 15 == 0 && count % 16 == 0 && count % 17 == 0 && count % 18 == 0 && count % 19 == 0 && count % 20 == 0; count++) { System.out.println(count); } } }