Menu
Question Index
...

Write a program to convert weight from one unit to another. Use only Milligrams, Grams, Kilograms, Tonnes, Pounds, Ounces for conversion and round off the result to decimals. Return -1 if conversion is not possible. 1 kg=2.20462 pounds, 1 pound=16 ounces, 1 kg=35.274 ounces.

Input (double, String, String) Output (double)
2.23, Kilograms, Milligrams 2230000.0
21.65, Ounces, Kilograms 0.61
68.5, Tonnes, Feet -1.0
56.2, Pounds, Ounces 899.2
6.5, Grams, Pounds 0.01
86.4, Milligrams, Grams 0.09



class ConvertWeightToOtherUnit
{
    public static void main(String s[])
    {
        double weight = 6.5;
        String input_unit = "Pounds", output_unit = "Grams";
        System.out.println("Converting " + weight + " " + input_unit + " to " + output_unit + " we get " + convertToOtherUnit(weight, input_unit, output_unit));

    }


    public static double convertToOtherUnit(double weight, String input, String output) {
    }
    

}

Doubts

Problems

Topic: Learn Arrays And Loops

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App