Hi, I need some help guys. I am getting an error with this code:
class SquareRoot
{
public static double sqrt(double a)
{
double g, h;
//throws exception if 'a' is negitive
if(a = 0)
{
throw new ArithmeticException("cannot process negitive numbers");
}
while(true)
{
if(Math.abs(g - h) < 1.0e-9)
{
return g;
}
else
{
g = (g + h)/2;
h = a/g;
}
}
}
}
class SquareRootNumbers
{
public static void main(
String args[])
{
for(int number = 1; number <= 9; number++)
{
System.out.println(number + " " + SquareRoot.sqrt(number));
}
try
{
System.out.println("-1 " + SquareRoot.sqrt(-1));
}
catch (ArithmeticException ignore)
{
System.out.println(ignore);
}
}
}
Thanks for the help guys!