Menu
Question Index
...


Write a program to balance the chemical equation given the input molecules and the output molecules. Note that the first two are the input molecules and the last two are the output molecules. Assume that the maximum number of molecules required for balancing is less than 10.

Input (String, String, String, String) Output (String)
BaCl2, Na2SO4, NaCl, BaSO4 BaCl2 + Na2SO4 = 2NaCl + BaSO4
CH4, O2, CO2, H2O CH4 + 2O2 = CO2 + 2H2O
HCl, FeS, FeCl2, H2S 2HCl + FeS = FeCl2 + H2S
NaCl, AgNO3, NaNO3, AgCl NaCl + AgNO3 = NaNO3 + AgCl
Na, H2O, NaOH, H2 2Na + 2H2O = 2NaOH + H2
SiO4, H2O, H4Si, O2 SiO4 + 2H2O = H4Si + 3O2

class BalancingTheEquation

{    public static void main(String s[])
    {
        System.out.println("Balanced equation : " + getEquation("BaCl2", "Na2SO4", "NaCl", "BaSO4"));

    }


public static String getEquation(String first, String second, String third, String fourth) {
//Write code here to get the balanced equation
}

//If required write any additional methods here
}

Doubts

Problems

Topic: Java HashMap Implementation

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App