0

I want to check it the first input argument is operator "+"

below is the code

if (args[0] == "+") {
    System.out.println("good");
} else {
    System.out.println("invalid expression");
}

but it always return false. something wrong with the code?

Will
  • 633
  • 11
  • 26

1 Answers1

2

You should compare strings using str.equals(..) method and not ==, which compares object adresses.

if (args[0].equals("+")) {
  :
}
MaxZoom
  • 7,619
  • 5
  • 28
  • 44
user2494817
  • 697
  • 4
  • 12