Answer to Question #233568 in Java | JSP | JSF for Sony

Question #233568
Single File Programming Question

Ram and Mohan are two brothers. They are not good at maths. So their father decided to give some assignments as a game so that they can enjoy as well as they can learn the concept of number systems. So he gave two numbers to them. One is the sum of two numbers, x and y, and another is the product of the same two numbers. Help them to write a code to find x and y.

Note:

The two numbers should be printed in ascending order.

Example 1

Input

56

Output

23

Explanation

If we sum the numbers 2 and 3 we get the first input value 5 and if we

java.util. G

Scanner(

sum

prod

( i

Il virtusacoetraining.examly.io is sharing your scre
1
Expert's answer
2021-09-05T08:43:20-0400
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("sum: ");
        int sum = in.nextInt();
        System.out.print("product: ");
        int product = in.nextInt();
        double sqrtD = Math.sqrt(Math.pow(-sum, 2) - (4 * product));
        double x1 = (sum + sqrtD) / 2;
        double x2 = (sum - sqrtD) / 2;
        System.out.println("x=" + x1 + " y=" + x2);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS