Menu
Topics Index
...
`

Given the difference of two numbers and the ratio of larger to smaller find those numbers


If you need explanation Read this topic

If you need Answer Take test on this topic

Write a program to find the two numbers. The difference of those two numbers and the ratio of larger number by smaller number is given.

Input (Integer, Integer) Output (String)
12, 5 LargerNumber = 15.0, SmallerNumber = 3.0
Difference = 15.0 - 3.0 = 12.0
Ratio = 15.0/3.0 = 5.0  
7, 3 LargerNumber = 10.5, SmallerNumber = 3.5
17, 6 LargerNumber = 20.4, SmallerNumber = 3.4
18, 4 LargerNumber = 24.0, SmallerNumber = 6.0
46, 8 LargerNumber = 52.57142857142857, SmallerNumber = 6.571428571428571



class FindNumbersFromDifferenceAndRatio
{
    public static void main(String s[])
    {
        System.out.println(findNumbers(30, 4));

    }


    public static String findNumbers(int difference, double ratioOfLargerBySmaller) {
    }

}
Topic: Basic Arithmetic Operators In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

To get the smallest number,logic is
smaller_number = (difference)/(ratioOflargerBySmaller-1)
larger_number = difference + smaller_number

Posted by Shashanka Mogaliraju    2015-03-16 09:20:57


Smaller number =difference /(ratio-1).   & larger number is difference+smaller number

Posted by Mohd Ajsam    2015-03-16 11:12:30


© meritcampus 2019

All Rights Reserved.

Open In App