{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

SixXorSeven

# SixXorSeven - is this first number for(int i = LOW_LIMIT...

This preview shows page 1. Sign up to view the full content.

/* * File: SixXorSeven.java * ---------------------- * This program displays the integers that * are divisible by either 6 or 7 but not both. * The lower and upper limits are defined as constants. * * Author: CS1MD3, Sept. 2008 */ import acm.program.*; i public class SixXorSeven extends ConsoleProgram { p public void run() { println("This program displays the integers between " + LOW_LIMIT + " and " + HIGH_LIMIT); println("that are divisible by either 6 or 7 but not both."); println(""); boolean isFirst = true;
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: /* is this first number? */ for (int i = LOW_LIMIT; i <= HIGH_LIMIT; i++) { if (((i % 6 == 0) || (i % 7 == 0)) && ((i % 6 != 0) || (i % 7 != 0))) { if (isFirst) { /* if first */ print(i); /* print number */ isFirst = false; } else { /* if not first */ print(", " + i); /* print ", " after the previous number */ } } } println("."); } /* lower and upper limits, constants */ private static final int LOW_LIMIT = 1; private static final int HIGH_LIMIT = 100; }...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online