Hi..sorry for late reply..,
you had not put $j++ in for loop and also some important prime or not prime echo statements..., I've modified it as following..:
<?php
// define class
class Calculator
{
//class variables:
var $i;
//Class member functions or methods:
function Isprime($number1)
{
$this->i=$number1;
if($this->i < 2)
{
echo "Enter a number > 2";
return false;
}
for($j=2;$j<=(($this->i)/2);$j++ )
{
if($this->i % $j ==0)
{
echo $this->i. " is not a prime";
return false;
}
}
echo $this->i. " is prime";
return true;
}
}
$num1=$_POST['number1'];
//Create a class instance:
$calc = new Calculator();
//Call class methods:
$calc->Isprime($num1);
//Display output:
?>
NOTE:
as you might be knowing,make sure that you post the value/number to be checked with name="number1" through a form from another file to the above discussed file..,
Aug 14, 2010