How would I be able to input a chemical compound in order to get the molecular mass of the compound while using the Stacks class to find the sum but not use the Scanner class?
//Please comment it you have any queries
Answer:
Firstly, there are multiple ways to give input from the user in java. If you do not to use the Scanner class, then you can use BufferedReader class instead in Java.
To input chemical compound without Scanner class, you can use below code
Syntax:
import java.util.*;
import java.lang.*;
import java.io.*;
public class Stacks
{
public static void main (String[] args) throws
java.lang.Exception
{
BufferedReader chemicalCompound = new
BufferedReader(new InputStreamReader(System.in));
// Reading data using readLine
String strChemicalCompound =
chemicalCompound.readLine();
}
}
// Note: To read other types, we use functions like Integer.parseInt(), Double.parseDouble(). EX
int size = Integer.parseInt(chemicalCompound.readLine());
Get Answers For Free
Most questions answered within 1 hours.