Tutorial Gateway

  • C Language
  • Java
  • R
  • SQL
  • MySQL
  • Python
  • BI Tools
    • Informatica
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • QlikView
  • Js

Java Program to Find Square root of a Number

by suresh

In this article we will show you, How to write a Java Program to Find Square root of a Number using Math.sqrt, and without using sqrt function with example.

Java Program to Find Square root of a Number Example 1

This program allows the user to enter integer value, and then finds square root of that number using math function Math.sqrt

// Java Program to Find Square root of a Number
import java.util.Scanner;

public class SqrtofNumber1 {
	private static Scanner sc;
	public static void main(String[] args) 
	{
		double number, squareRoot;
		sc = new Scanner(System.in);
		
		System.out.print(" Please Enter any Number : ");
		number = sc.nextDouble();		
		
		squareRoot = Math.sqrt(number);
		
		System.out.println("\n The Square of a Given Number  " + number + "  =  " + squareRoot);
	}
}

OUTPUT

Java Program to Find Square root of a Number 1

Java Program to Find Square root of a Number Example 2

In this Program we are using the math function Math.pow to find the square root of a number. As we all know √number = number½

// Java Program to Find Square root of a Number
import java.util.Scanner;

public class SqrtofNumber2 {
	private static Scanner sc;
	public static void main(String[] args) 
	{
		double number, squareRoot;
		sc = new Scanner(System.in);
		
		System.out.print(" Please Enter any Number : ");
		number = sc.nextDouble();		
		
		squareRoot = Math.pow(number, 0.5);
		
		System.out.println("\n The Square of a Given Number  " + number + "  =  " + squareRoot);
	}
}

OUTPUT

Java Program to Find Square root of a Number 2

Thank You for Visiting Our Blog

Placed Under: Java Programs, Java Tutorial

Stay in Touch!

Sign Up to receive Email updates on Latest Tutorials

  • C Programs
  • Java Programs
  • SQL FAQ’s
  • Python Programs
  • SSIS
  • Tableau
  • JavaScript

Copyright © 2019 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy