Input 2 integers and print the sum of their square roots using mathematical functions in Java
Mathematical Functions - Question 2
In this question, we will see how to input two integer numbers and print the sum of their square roots in Java programming using the mathematical functions. To know more about mathematical functions click on the mathematical functions lesson.
Q2) Write a program in Java to input two integer numbers and print the sum of their square roots using the sqrt() function.
Program
import java.util.Scanner;
public class Q2
{
public static void main(String args[])
{
int a,b;
double s;
Scanner sc=new Scanner(System.in);
System.out.println("Enter 2 integer numbers");
a=sc.nextInt();
b=sc.nextInt();
s=Math.sqrt(a) + Math.sqrt(b);
System.out.println("Sum of the square root = " + s);
}
}
Output
Enter 2 integer numbers 25 9 Sum of the square root = 8.0