-
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.
Parin
-
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
eschew obfuscation
-
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 ?
eschew obfuscation
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks