0

im trying to understand what's the type of user input whether it is a number or character or string. how can i do the task wanted in comment?

public static void main(String[] args) {
        Calculator calculator=null; 
        Scanner num = new Scanner(System.in);
        System.out.println("press C to clear.  press E to terminate. ");
        while (true) {
                String input = num.nextLine();
                UserInputHandler.handleuserinput(input, calculator);
// if the input is a number do some thing.
//if the input is a character do some thing else.
   }
}
Elahe
  • 1
  • 1
  • 1
    Does this answer your question? [What's the best way to check if a String represents an integer in Java?](https://stackoverflow.com/questions/237159/whats-the-best-way-to-check-if-a-string-represents-an-integer-in-java) – sleepToken Feb 12 '20 at 14:26
  • I can't flag this as a duplicate for both parts - but converting a String to an int / char has certainly been addressed on this site - as well as all over the web. – sleepToken Feb 12 '20 at 14:27
  • You may check StringUtils from Apache commons lib https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html. It has some methods like isNumeric(),getDigits() etc. using them you can write your own code. – kalpesh Feb 12 '20 at 14:40

0 Answers0