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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • broception
    New Member
    • Feb 2013
    • 4

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

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

    Code:
    import javax.swing.JOptionPane;
    
    public class morePractice {
    
    	public static void main(String[] args) {
    		String str;
    		int num1;
    		
    		str=JOptionPane.showInputDialog("Enter phrase");
    		num1=Integer.parseInt(str);
    		
    	
    	}
    
    }
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Code:
    num1=Integer.parseInt(str);
    converts the input to an int which fails if the input is not an int, like for example lajflho142323kj lkhaf.
    If you want the input to accept the mixture then don't do Integer.parseIn t

    Comment

    Working...