0

I want to input something like: number23 using JOptionPane, but all I know how to do is either input a number or input a string.
How do I input word + number?

What I have so far:

import javax.swing.JOptionPane;

public class morePractice {

    public static void main(String[] args) {
        String str;
        int num1;
        int total=0;
        char letter;

        str=JOptionPane.showInputDialog(null,"Enter phrase");

        for(int i=0;i<str.length();i++){
            letter=str.charAt(i);
            if(letter>='A'&&letter<='Z'){
                total++;
            }

        }
        JOptionPane.showMessageDialog(null,"There are " + total + " upper case letters");

    }

}
Nandu
  • 3,076
  • 8
  • 34
  • 51
  • Take a look at [this](http://stackoverflow.com/questions/14783836/joptionpane-and-reading-integers-beginner-java/14784096#14784096) – MadProgrammer Mar 05 '13 at 07:48

1 Answers1

0

Use Regular Expression
Try this approach

String s = "Number23";
System.out.print(s.replaceAll("[^0-9]","")); 

it gives you just a number

or s.replaceAll("[^a-z]","") gives you just characters

Azad
  • 5,047
  • 20
  • 38
  • Ah thank you! I didn't even know you could do strings like that. Thanks alot! – broception Mar 05 '13 at 18:02
  • @broception: Please accept the answer, ream about this at [***`stackoverflow.com/about`***](http://stackoverflow.com/about) – Azad Aug 22 '13 at 11:15