-1

I am trying to use the value of a String obtained through JOptionPane. However, there is a problem with reading the String. What am I doing wrong here?

import javax.swing.JOptionPane;
public class convertNumber123 {
        public static void main(String[] args){
            String numsystem1;
            numsystem1 = JOptionPane.showInputDialog("Please enter the numeral system that you want to convert from: binary, octal, decimal or hexadecimal."); 
            if (numsystem1 == "Binary" || numsystem1 == "Octal" || numsystem1 == "Decimal" || numsystem1 == "Hexadecimal")
                System.out.println (numsystem1 + "it is!");
            else 
                System.out.println ("Please, enter the correct system name.");
        }
}   
  • 3
    Your question will be closed soon... But you can't compare Strings with `==` you must use the `.equals()` method. So like this... `numsystem1.equalsIgnoreCase("Binary") || ....` – 3kings May 03 '16 at 15:21
  • Thanks a lot, my friend! – daniilcul8r May 03 '16 at 15:29

2 Answers2

2

The way you are comparing strings is wrong. In java you have to use the .equals() method like this

if (numsystem1.equals("Binary") || numsystem1.equals("Octal") || numsystem1.equals("Decimal") || numsystem1.equals("Hexadecimal"))
Rafael Almeida
  • 5,142
  • 2
  • 20
  • 33
-1

Apparently, I was using == instead of equals() method. That was the problem.