Write a program to input three numbers and print the sum of
The square of the smallest and largest number entered. java math function only plz help
Answers
Answer:
class sum
{
void main (int a,int b,int c)
{
int k=Math.min(a,b);
double small=Math.pow(Math.min(k,c),2);
int j=Math.max(a,b);
double lar=Math.pow (Math.max(j,c),2);
double sum=lar+small;
System.out.println(sum);
}
}//PLEASE MARK ME AS BRAINLIEST
Solution:
The given problem is solved in Java.
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int a, b, c, max, min, sum;
System.out.print("Enter first number: ");
a = sc.nextInt();
System.out.print("Enter second number: ");
b = sc.nextInt();
System.out.print("Enter third number: ");
c = sc.nextInt();
max = Math.max(a, Math.max(b, c));
min = Math.min(a, Math.min(b, c));
sum = max * max + min * min;
System.out.println("Required sum: " + sum);
}
}
Explanation:
- We ask the user to enter three numbers.The numbers are taken as input using Scanner class.Then using Math.max() and Math.min() function, the largest and the smallest number is obtained.The sum of largest and smallest element is stored in another variable which is then displayed on the screen.
Refer to the attachment for output.
![](https://hi-static.z-dn.net/files/d70/7b37d1d1effa20c543750330a89c3149.png)