hi i have a question. i am trying to find square root through Babylonian method.
so far i have done this ....it works fine sometimes but it goes to infinite loop printing the same value again and again.
is there any way i can tell compiler if i am printing same output please abort??
or i can check every 5 lines..if i am producing same output then please System.exit(0);????
many thanks in advance
public class roughwork2
public static void main(String args)
System.out.println("Please enter a number");
Scanner readinput = new Scanner(System.in);
double number = readinput.nextDouble();
double guess = number/2;
for(double i = 0 ; ((number)/Math.pow(guess, 2) != (int) 1 ); i++)
guess = (( number/guess ) + guess) / 2 ;
System.out.printf("% ,.2f\n", guess);