Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * Purpose: This funny number summer sums numbers in a funny way, and it's meant
- * to provide an example of how to desk check a program.
- *
- *
- * @author James P. Burke
- *
- */
- public class FunnySum {
- /**
- * The main method sums some numbers and outputs some progress along the way.
- * @param args
- */
- public static void main(String[] args) {
- int a;
- int x = 0;
- int y = 0;
- int r = 0;
- while (x < 10) {
- a = x * 2;
- r = a % 3; // r is set to the remainder of a divided by 3
- switch (r) {
- case 0:
- y += a;
- System.out.println(a + " must be divisible by three!");
- break;
- case 1:
- y += x;
- break;
- case 2:
- y += r;
- break;
- default:
- System.out.println("We should never actually get here.");
- break;
- }
- x ++;
- }
- System.out.println("The sum is " + y);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement