fork(1) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7. private static boolean isDigitInt(String s) throws NumberFormatException {
  8. try {
  9. Integer.parseInt(s);
  10. return true;
  11. } catch (NumberFormatException e) {
  12. return false;
  13. }
  14. }
  15.  
  16. private static boolean isDigitDouble(String s) throws NumberFormatException {
  17. try {
  18. Double.parseDouble(s);
  19. return true;
  20. } catch (NumberFormatException e) {
  21. return false;
  22. }
  23. }
  24.  
  25. public static void main (String[] args) throws java.lang.Exception
  26. {
  27. Scanner in = new Scanner(System.in);
  28. String x;
  29. int s=0;
  30. x=in.nextLine();
  31. String[] y=x.split(" ");
  32. for(int i=0;i<y.length;i++){
  33. if(isDigitInt(y[i]) || isDigitDouble(y[i])){
  34. s++;
  35. }
  36. }
  37. System.out.print(s);
  38. }
  39. }
Success #stdin #stdout 0.06s 4386816KB
stdin
abc 123 42 6 5.5
stdout
4