Saved Bookmarks
| 1. |
Write a program to calculate square root of a number using library function. |
|
Answer» java.util.Scanner;public CLASS SquareRoot{public static double sq(int n){double sqrt = Math.sqrt(n);return sqrt;}public static void main(){Scanner sc = new Scanner(System.in);int n = sc.nextInt;System.out.println("The entered number is: "+n);int ans = sq(n);System.out.println("The SQUARE root of given number is: "+ans);}}• The FUNCTION used here from one of the library functions - Math.sqrt()• We are ALSO USING Scanner class in the above program. |
|