By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,804 Members | 1,364 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,804 IT Pros & Developers. It's quick & easy.

how to do user input mix of numbers and letters using JOptionPane

P: 4
What i have so far.
I'm trying to get it to where i can enter anything for example: lajflho142323kjlkhaf
but the program blows up if i do a mix of letters and numbers

Expand|Select|Wrap|Line Numbers
  1. import javax.swing.JOptionPane;
  3. public class morePractice {
  5.     public static void main(String[] args) {
  6.         String str;
  7.         int num1;
  9.         str=JOptionPane.showInputDialog("Enter phrase");
  10.         num1=Integer.parseInt(str);
  13.     }
  15. }
Mar 5 '13 #1
Share this Question
Share on Google+
1 Reply

P: 13,264
Expand|Select|Wrap|Line Numbers
  1. num1=Integer.parseInt(str);
converts the input to an int which fails if the input is not an int, like for example lajflho142323kjlkhaf.
If you want the input to accept the mixture then don't do Integer.parseInt
Mar 6 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.