Prime Number Answer
Full Java Application
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package s2s.javacourse; /** * * @author Selvyn */ public class PrimeNumberGenerator { public static void main(String args[]) { if( args.length < 2 ) { System.out.println("java s2s.javacourse.PrimeNumberGenerator <lower> <higher>"); System.exit(1); } int lower = Integer.parseInt(args[0]); int upper = Integer.parseInt(args[1]); for (int idx = lower; idx < upper; idx++) { if(idx == 0 || idx == 1) { System.out.println(idx + " is NOT prime number"); } else { boolean isPrimeNo = true; int midway = idx / 2; for(int i = 2; i <= midway; i++) { if(idx % i == 0) { System.out.println(idx + " is NOT prime number"); isPrimeNo = false; break; } } if(isPrimeNo) { System.out.println(idx + " is prime number"); } }//end of else } } }