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 8510519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:43:40+00:00 2026-06-11T03:43:40+00:00

I have a weird problem in java. I am trying to make a math

  • 0

I have a weird problem in java. I am trying to make a math expression calculator which would evaluate an infix math expression and return the final result on the screen. I have used stacks to accomplish the task and so far, I was using a hardcoded string for input, but then I changed it to command line arguments for the same purpose. My problem is that, the stacks which I am using just won’t push values into themselves from the commandline inputs although the datatype and the strings are exactly the same.

Here is the code to push data into the stack.

public class Expression 
{
    public static void main(String argv[]){

        Stack<String> operator = new Stack<String>();
        Stack<String> operand = new Stack<String>();

        /*
        String push[] = new String[argv.length];
        for (int i = 0; i<push.length; i++){
            push[i] = argv[i];
        }
        */

        for(int i = 0; i<argv.length; i++){
            if(argv[i] == "+" || argv[i] == "-" || argv[i] == "*" 
               || argv[i] == "/" || argv[i] == "^") {
                operator.push(argv[i]);
            } else if(argv[i] == "0" || argv[i] == "1" || argv[i] == "2" 
                      || argv[i] == "3" || argv[i] == "4" || argv[i] == "5" 
                      || argv[i] == "6" || argv[i] == "7" || argv[i] == "8" 
                      || argv[i] == "9") {
                operand.push(argv[i]);
            }
        }

        System.out.println(operand);
        System.out.println(operator);

        Stack<String> result = evaluateStack(operand, operator);
        System.out.println(result.toString());
    }
}

When I used the debugger using harcoded string, it was showing that the stack was filled normally, but with commandline arguments, it always shows the stacks with 0 elements even when the for loop is completed. What am I doing wrong?

  • 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-11T03:43:42+00:00Added an answer on June 11, 2026 at 3:43 am

    Be sure when to use “==” and when to use “equals”….

         "==" will be used to check the equality of the String objects 
    

    and

        "equals(...)" will be used to the check the content of the String objects.
    

    your problem will be solved when you use the equals(…) method for checking the operands

    operators

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

Sidebar

Related Questions

I have this weird problem in java when trying to fetch records from MYSql
I have a weird problem with a Java Gregorian Calendar: SimpleDateFormat sdf = new
I have a weird problem, so I thought I would ask and see if
I have another weird problem which I have not been able to solve in
I have a weird problem. While running my Android application, I receive Exception: java.lang.ClassCastException:
I have a WEIRD problem with Future.get() in Java. It returns always with an
I'm trying to embed groovy in java application and got a weird problem. Let's
I have weird problem. I'm using Eclipse for writing J2EE (java, jsf, javascript) application
I have a weird problem. My java applet work fine in my IDE (Eclipse),
i have a weird problem. I am trying to write simple Client - Server

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.