Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9134121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:36:18+00:00 2026-06-17T08:36:18+00:00

given a file with input: Formula: m = (y – c) / x Formula:

  • 0

given a file with input:

Formula: m = (y - c) / x
Formula: m = y + c^2

I want to implement each formula in java to solve for m so that in this case I will end up with 2 answers. I have to do this as coding for each formula individually will be too time consuming for all the formulae I require.

So far my code below just detects and isolates each formula. I have also removed user input for the purposes of this question.

int y = 8;
int c = 2;
int x = 2;

    try{
       FileInputStream fstream = new FileInputStream("Filename");

        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;

        while((strLine = br.readLine()) != null){
            if(strLine.startsWith("Formula")){
                String standAloneFormula = strLine.replace("Formula: ", "");
                System.out.println(standAloneFormula);
            }
        }
    }
    catch(Exception e){
        System.out.print(e);

The main problem that I am having is accessing the code and then applying the integer values to the string values. What would be the easiest way to solve for, in this case, m?

Any ideas, links or relevant code will be appreciated.

Regards.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:36:19+00:00Added an answer on June 17, 2026 at 8:36 am

    Try creating a simple object model for equations using the composite pattern. You can break every input line down to being a single expression possibly containing other expressions as operands. Then you can define a method calculate(HashMap<String, Integer> values) in all of your classes, where values is just the definition of all the variables that might occur in your calculation. By calling the method recursively you should in the end get the result.

    You will need one class for each mathematical operation you wish to support, e.g. Addition, Subtraction, Negation, …

    Parsing the string and constructing the object hierarchy is the most difficult task actually. Would be a lot easier with a polish notation or something more easy to parse.

    Overall it might be adviseable to use a tool more suited to solving mathematical problems rather than trying to code something yourself. Maybe even Excel might help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to read line-by-line from a given input file,, process each line (i.e.
So basically I would like somehow that given an audio file as input (most
Given an input file of text lines, I want duplicate lines to be identified
I'm implementing a C++ program that can programmatically instantiate objects given an input file
Given this input file: SectionMarker and some random text here this is the text
Given input file z b a f g a b ... I want to
This program produces the output I expect when given an input file of text
Given the input XML file: <acctInfo> <wfInfo> <aaa>1</aaa> <bbb>1</bbb> <ccc>1</ccc> <ddd>1</ddd> <eee>1</eee> </wfInfo> <acctInfo>
Given some source file (or more generic - input stream), I need to find
For any given file data size, I want to be able to resize (or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.