Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Sqrt {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- double num = sc.nextInt();
- sc.close();
- boolean flag = true;
- double left = 0;
- double right = 1e10;
- double mid = 0;
- double root = 0;
- while (flag) {
- mid = (left + right) / 2;
- if (mid * mid - num < 0.00001) {
- flag = false;
- root = mid;
- } else {
- if (mid * mid > num)
- right = mid;
- else
- left = mid;
- }
- }
- System.out.println(root);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement