0

Hello I have got a little "problem" ... I just seems weird to me that when you check the code below that it says false if I type same number twice in the dialog fields.

I am kinda new to Java but not to programming itself and it does not make any sense.

Thanks in advance

    import javax.swing.*;


public class Praeinkrement {

    public static void main(String[] args) {

        String a = JOptionPane.showInputDialog("Zahl a");
        String b = JOptionPane.showInputDialog("Zahl b");


        Double c = Double.parseDouble(a);
        Double d = Double.parseDouble(b);

        boolean e, f;
        e = (c == d);
        f = (c < d);

        JOptionPane.showMessageDialog(null, e + "\n" + f);

    }
}

1 Answers1

0

Use .equals for value checking,

public static void main(String[] args) {

          String a = JOptionPane.showInputDialog("Zahl a");
            String b = JOptionPane.showInputDialog("Zahl b");

            boolean c = (a.equals(b));

            JOptionPane.showMessageDialog(null, c);
    }
Balasubramanian
  • 700
  • 7
  • 26