import javax.swing.*;
public class Sqroot
{
public static void main(String args[])
{
String s=JOptionPane.showInputDialog("Enter a number");
double no=Double.parseDouble(s);
System.out.println("Square root of " + no +"="+Sqroot(no));
}
public static double Sqroot(double no)
{ //square root Babylonian method
double esti=no;
double divi=2;
//below 100 is arbitrary, for very small decimals j values must be large
for(int j=0; j<100; j++)
{
esti=no/divi;
esti=(esti+divi)/2; //find average estimate & divisor
divi=esti;
}
return esti;
}
}
Wednesday
//
Labels:
JAVA PROJECTS
//
0
comments
//
0 comments to "BABYLONIAN METHOD FOR DETERMINING A SQUARE ROOT OF A NUMBER IN JAVA"
Powered by Blogger.
Blog Archive
-
▼
2011
(50)
-
▼
August
(12)
- INTRODUCTION TO JAVA
- ABSTRACTION
- INHERITANCE
- ENCAPSULATION
- SIMPLE JAVA PROGRAM
- BABYLONIAN METHOD FOR DETERMINING A SQUARE ROO...
- TRIGONOMETRIC FUNCTIONS CALCULATED USING MCLAUREN ...
- PROJECT ON RESERVATION
- CALCULATOR USING JAVA
- MANAGEMENT OF SCHOOL RECORDS USING JAVA
- MULTITHREADED MATRIX MULTIPLICATION IN JAVA
- PROJECT ON LIBRARY SYSTEM IN JAVA
-
▼
August
(12)
Post a Comment