Check07D - boolean flag = true; while (index <...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.Scanner; import; import java.math.BigInteger; import type.lib.ToolBox; i public class Check07D { public static void main(String[] args) { PrintStream out = System.out; Scanner in = new Scanner(; out.print("Enter an integer greater than 1 . .. "); int prime = in.nextInt(), index = 2; ToolBox.crash(prime <= 1, "Integer must be greater than 1!"); final int MAX = (int) Math.sqrt(prime), TEN = 10;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: boolean flag = true; while (index &lt; MAX &amp;&amp; flag) { flag = prime % index &gt; 0; index++; } out.println(&quot;The primality of your entry is:&quot;); out.println(&quot;- Using the direct algorithm: &quot; + flag); flag = new BigInteger(String.valueOf(prime)).isProbablePrime(TEN); out.println(&quot;- Using the BigInteger class: &quot; + flag); } }...
View Full Document

This note was uploaded on 09/16/2011 for the course CSE CSE 1020 taught by Professor Burton,ma during the Fall '10 term at York University.

Ask a homework question - tutors are online