Skip to content

Commit 9f869bf

Browse files
I added new Program on Math Folder
1 parent 6bd3353 commit 9f869bf

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Math/NEWTON_RAPHSON.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.util.Scanner;
2+
3+
4+
//This method is used to find the square root of a number
5+
// Formula of this method is: root= (x+n/x)2; x= guessed number, n= number to find its sqrt root
6+
7+
8+
public class NEWTON_RAPHSON {
9+
public static void main(String[] args) {
10+
Scanner sc=new Scanner(System.in);
11+
System.out.println("Enter a number to find its square root");
12+
int num= sc.nextInt();
13+
double root;
14+
double x=num;
15+
while (true){
16+
root= (x+num/x)/2;
17+
if(Math.abs(x-root)<1)
18+
break;
19+
x=root;
20+
}
21+
System.out.println(root);
22+
}
23+
}

0 commit comments

Comments
 (0)