Computer Science 523
Advanced Programming
Summer 2014, The College of Saint Rose
LittlePrimes BlueJ Project
Click here to download a BlueJ project for LittlePrimes.
LittlePrimes Source Code
The Java source code for LittlePrimes is below. Click on a file name to download it.
/* * Example LittlePrimes: print whether a small number (1-10) is prime or composite. * Demonstrates multiple cases performing the same code in a switch statement. * * Jim Teresco, The College of Saint Rose, CSC 202, Fall 2012 * * $Id: LittlePrimes.java 2366 2014-05-20 02:33:22Z terescoj $ */ import java.util.Scanner; public class LittlePrimes { public static void main(String[] args) { // we'll read in a number with a Scanner Scanner kbd = new Scanner(System.in); System.out.print("Enter a number 1-10: "); int number = kbd.nextInt(); switch (number) { case 1: case 4: case 6: case 8: case 9: case 10: System.out.println(number + " is composite."); break; case 2: case 3: case 5: case 7: System.out.println(number + " is prime."); break; default: System.out.println(number + " is out of the allowed range (1-10)"); break; } } }