Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Java by hgates ( 6 years ago )
/**
 * Print out all primes less than the input value 
 * @hgates
 * @12/1/20
 */

import java.util.Scanner;
public class PrimeSearch
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        
        System.out.println("Please enter a value for a max prime number : ");
        
        int n = in.nextInt();
        boolean isPrime=true;
        for(int i = 2; i <= n; i++)
        {
            for(int div = 2; div <= i/2; div++)
            {
                if(i % div == 0) 
                {
                    isPrime=false;
                    break; 
                }
                
            }
            if(isPrime==true)
            {
                System.out.println(i+" is prime");
            }
            isPrime=true;
        }
    }
}

 

Revise this Paste

Your Name: Code Language: