// CuriousMultipleOf7.java class CuriousMultipleOf7 { public static void main(String[] args) { System.out.println("This program uses a 'for' loop to compute the"); System.out.println("answer to the following problem:"); System.out.println(); System.out.println("List every integer between 1 and 1000 which is"); System.out.println("1 greater than multiples of 2, and 3, and 4, and 5,"); System.out.println("and 6, but which is also exactly a multiple of 7."); System.out.println(); System.out.println("Like many such Java programs, this does not use"); System.out.println("any clever math at all -- it just checks every"); System.out.println("possible number in that range and prints out the"); System.out.println("ones which pass the test!"); System.out.println(); for (int n=1; n<=1000; n++) { if (((n % 2) == 1) && ((n % 3) == 1) && ((n % 4) == 1) && ((n % 5) == 1) && ((n % 6) == 1) && ((n % 7) == 0)) { System.out.println(n); } } } /////////////////////////////////// // readString, readInt, readDouble /////////////////////////////////// public static String readString() { java.io.InputStreamReader isr = new java.io.InputStreamReader(System.in); java.io.BufferedReader d = new java.io.BufferedReader(isr); try { return d.readLine(); } catch (Exception e) { return "error"; } } public static int readInt() { return Integer.parseInt(readString()); } public static double readDouble() { return Double.valueOf(readString()).doubleValue(); } }