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

  • SEARCH
  • Home
  • 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 8621339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:47:54+00:00 2026-06-12T06:47:54+00:00

Yo – trying to get back into java so decided to create a calculator.

  • 0

Yo – trying to get back into java so decided to create a calculator.

It’s suppose to work like this:

1) Get input from the user in the form of a string
-> This input is stored as a string, for example:
12+89

2) Split the string according to operator position and ensure that whatever comes before this operation is converted to an integer and stored

3) Once string has been passed through, compute the value

Im pretty sure Im making this more complicated than what it actually is :p here is the code so far:

// Split String, count digits in string
public static void spitStrg() {
    int numDigits = 0;
    int numOperators = 0;
    for (int i = 0; i < input.length(); i++) {
        if (Character.isDigit(input.charAt(i))) {
            numDigits++;
        }
        else if (input.charAt(i) == '+') {
            System.out.println( "Position of operator: "+i);
            numOperators++;
        }
    }
    System.out.println("Number of Digits: "+numDigits);
    System.out.println("Number of Operators: "+numOperators);
}

// Create a number from cut off point
public static void createNum(int startPoint, int operatorPosition) {
    String tempNum = "";

    for (int j = startPoint; j < operatorPosition; j++) {
        tempNum = tempNum + input.charAt(startPoint);
    }
}

Does anyone have any other suggestions on how to handle this? I.e. ask for one number at a time and then the operator or store everything in a vector to reflect a growing number of digits and operators?

  • 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-12T06:47:55+00:00Added an answer on June 12, 2026 at 6:47 am

    not sure if this is ok for you. (or a cheat?)

    you just let user input the whole expression as a string. 23+33-34*2^2

    then you could :

    try {
            final ScriptEngine engine = new ScriptEngineManager().getEngineByName("js");
            final Object result = engine.eval("23+33-34*2^2");
            System.out.println(result);
        } catch (final ScriptException e) {
    
            e.printStackTrace();
        }
    

    run above code, will give you:

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

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
I'm trying to craft a Java regular expression to split strings of the general
My NSXMLParser breaks on this string: <title>AAA &#8211; BCDEFGQWERTYUIO</title> I parsed it in this
I am getting the value from web service like &gt;&lt;&amp;&nbsp; etc. I want to
I am currently scraping some data from the internet and converting into xml documents.
An extension to my previous question: Text cleaning and replacement: delete \n from a
I am reading some og tags from sites but I can't seem to decode
Possible Duplicate: replace all occurrences in a string I found this question/answer: Use JavaScript
i have this code: <?php $valid_ext = array(pdf, doc); $args = array( 'post_type' =>
I would like to count the length of a string with PHP. The string

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.