Hi,
Cosidering the following code ....i want to store the output values into an array..
can anyone pliz help.........
import java.io.*;
import abr.srw.*;
public class Prime1
{
// This method tests whether a given number is prime or not.
public static boolean isPrime ( int num )
{
boolean prime = true;
int limit = (int) Math.sqrt ( num ); // limit is set to the sqrt of the number
for ( int i = 2; i <= limit; i++ ) // range is set from 2 to the limit
{
if ( num % i == 0 ) // num is checked if it is divisible by numbers equal to
{ // or lower than its sqrt
prime = false;
break;
}
}
return prime;
}
// ************** Main Program ***************************** //
public static void main ( String[] args ) throws Exception
{
SimpleReader in = new SimpleReader();
System.out.print("Enter a number ");
int num = in.readInt(); // number is read in.
for ( int i = 2; i <= num; i++ )
{
if ( isPrime ( i ) ) // all numbers from i=2<=num is tested with Prime tester
{
System.out.print(i);// prints out all prime numbers <= num :Question
//How can I store this values into an array?
}