import java.util.*; import java.io.*; public class PrimeNumber { public static void main(String[] args)throws IOException{ Scanner input = new Scanner(System.in); long n = 2; long sum = 0; long limit = 0; while (true) { System.out.println("Enter the limit: "); limit = input.nextLong(); if (limit <= 0){ System.out.println("The number must be positive: "); limit = input.nextInt(); } while (n < limit){ if (Prime(n)==true) { sum = sum + n; } n++; } System.out.println("The sum of the primes below " +limit+ " is: " +sum); } } public static boolean Prime(long number)// Checks to see if a number is prime { for (int i = 2; i <= number/2; i++) { if (number % i == 0) // if number is divisible by any number that is <= half of it, then number is NOT prime { return false; } } return true; // If number isn't divisible by any number other than itself and one, then number IS prime } }

This post has been edited by **Flukeshot**: 06 July 2013 - 07:11 PM

Reason for edit:: code tags