How do you take a negative in through...
I am trying to write a program that takes in a double (x)and an integer (n) and returns x^n. The problem I run into is input a negative number, either for x or n. Is this code sufficient? (assuming I have imported the necessary packages)
String userInput = JOptionPane.showInputDialog("Please enter x");
double x = Double.parseDouble(userInput);
userInput = JOptionPane.showInputDialog("Please enter n");
int n = Integer.parseInt(userInput);
If there is an easier way of taking in a negative using JOptionPane, I would LOVE to here it.
Thanks for your time.
There isn't. You could use the version of JInput Dialog
that takes, and returns an Object (Double in your case).
If it's simpler is another question though
Ahh that may very well work. Thank ya kindly =)
Actually, after running many-a-tests I have concluded that it does indeed take in the negative and parses it.
Of course but the issue was simplification, wasn't it ?
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center