BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Java Program to Find square root of a Number without sqrt

Last Updated: February 23, 2019 by Chaitanya Singh | Filed Under: Java Examples

Finding square root of a number is very easy, we can use the Math.sqrt() method to find out the square root of any number. However in this tutorial we will do something different, we will write a java program to find the square root of a number without the sqrt() method.

Java Example to find the square root without sqrt() method

In the following program we have created a method squareRoot(), in the method we have written a equation which is used for finding out the square root of a number. For the equation we have used do while loop.

package com.beginnersbook;
import java.util.Scanner;
class JavaExample { 

    public static double squareRoot(int number) {
	double temp;

	double sr = number / 2;

	do {
		temp = sr;
		sr = (temp + (number / temp)) / 2;
	} while ((temp - sr) != 0);

	return sr;
    }

    public static void main(String[] args)  
    { 
	System.out.print("Enter any number:");
	Scanner scanner = new Scanner(System.in);
	int num = scanner.nextInt(); 
	scanner.close();

	System.out.println("Square root of "+ num+ " is: "+squareRoot(num));
    } 
}

Output:
Java Program to find out the square root of a given number

Related Java Examples

1. Java program to check perfect square number
2. Java program to break a number in digits
3. Java program to find GCD of two numbers
4. Java program to display fibonacci series

Top Related Articles:

  1. Peterson Number Program in Java
  2. Java Program to Calculate average using Array
  3. Automorphic Number Program in Java
  4. Java Program to break Integer into Digits
  5. Java Program to Print Sandglass Star Pattern

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Java Examples

  • Check Odd-even
  • Linear Search
  • Binary Search
  • Floyd's Triangle
  • Reverse number
  • Random Number
  • first n prime numbers
  • Disp prime Numbers
  • Check Prime number
  • Palindrome String
  • Find factorial
  • Sum of elements of Array
  • Area of rectangle
  • Area of Square
  • Area of Triangle
  • Circle

Tutorials

  • Java Tutorial
  • OOPs Concepts
  • Java String
  • Exception handling
  • Java Multithreading
  • Java I/O
  • Java Serialization
  • Java Regex
  • Java AWT
  • Java Swing
  • Java Enum
  • Java Annotations

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap