We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 4c74e72 + 2ae2652 commit 6c6f1afCopy full SHA for 6c6f1af
Numbers/SquareRoot.java
@@ -0,0 +1,24 @@
1
+import java.io.*;
2
+public class SquareRoot
3
+{
4
+ /* Time Comeplexity:-O(lg(n))
5
+ Space Complexity:- O(1)**/
6
+ public static void main(String args[])throws IOException
7
+ {
8
+ InputStreamReader read=new InputStreamReader(System.in);
9
+ BufferedReader in=new BufferedReader(read);
10
+ System.out.println("Enter your number");
11
+ int n=Integer.parseInt(in.readLine());
12
+ int x=n;
13
+ if(x<=1)
14
+ System.out.println(x);
15
+ int sqrt=x/2;
16
+ int quotient=x/sqrt;
17
+ while(sqrt>quotient)
18
19
+ sqrt=(sqrt+quotient)>>1;//bitwise operator used to make the process faster
20
+ quotient=x/sqrt;
21
+ }
22
+ System.out.println("The square root of the number "+n+" is = "+sqrt);
23
24
0 commit comments