Wednesday, October 28, 2009

Oh, well. Carry on then.

/* Sorry sir, I almost forgot. I made a test. The outputs should be the same. Mind the comments. You look perplexed. Should I write a manual? Five or ten pages? */
public class FooBarBaz
{
public static void main(String[] args)
{
String foo;
String bar;
String baz;
int n;
n = 1; //set n to one to align 50 and 1
for (int i=50; i>0; --i) // the loop counts down but the game ticks forward... from zero, oops.
{
// System.out.println(n); // Remove comment to print n on a separate line from the ducks and geese
if (n%3==0 && !(n%3==0 && n%5==0) && !(n%3==0 && n%7==0) && !(n%3==0 && n%5==0 && n%7==0))
System.out.println("N is equal to " + n + " I is equal to " + i + " foo");
// foo, foo bar, foo bar baz, foo baz
else if (n%5==0 && !(n%5==0 && n%5==0) && !(n%5==0 && n%7==0) && !(n%3==0 && n%5==0 && n%7==0))
System.out.println("N is equal to " + n + " I is equal to " + i + " bar");
// bar, bar baz
else if (n%7==0 && !(n%7==0 && n%5==0) && !(n%3==0 && n%7==0) && !(n%3==0 && n%5==0 && n%7==0))
System.out.println("N is equal to " + n + " I is equal to " + i + " baz");
// baz & null makes 8 or 2^3, 4 remain unaccounted for.
else if (n%3==0 && n%5==0 && n%7==0)
System.out.println("N is equal to " + n + " I is equal to " + i + " foo bar baz");
// foo bar baz accounted for, 3 left, sir requesting leave. I am not required for this maximum i sir. 3*5*7 > 50, QED.
else if (n%3==0 && n%5==0)
System.out.println("N is equal to " + n + " I is equal to " + i + " foo bar");
// foo bar present and accounted for sir! c--
else if (n%3==0 && n%7==0)
System.out.println("N is equal to " + n + " I is equal to " + i + " foo baz");
// foo baz, sir bar baz is the only one unaccounted for sir!
else if (n%5==0 && n%7==0)
System.out.println("N is equal to " + n + " I is equal to " + i + " bar baz");
// bar baz reporting sir! All present and accounted for sir!
else
System.out.println("N is equal to " + n + " I is equal to " + i);
n++;
}
}

}

No comments:

Post a Comment