fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Scanner sc = new Scanner(System.in);
  13.  
  14. while(sc.hasNext()) {
  15. int numbers = 0;
  16. int words = 0;
  17. String line = sc.nextLine();
  18. String[] parts = line.split(" ");
  19.  
  20. for (String part:parts) {
  21. if(isInteger(part)) numbers++;
  22. else words++;
  23. }
  24.  
  25.  
  26. System.out.println(numbers + " " + words);
  27. }
  28. }
  29.  
  30. private static boolean isInteger(String s) {
  31. try {
  32. Integer.parseInt(s);
  33. } catch(NumberFormatException e) {
  34. return false;
  35. } catch(NullPointerException e) {
  36. return false;
  37. }
  38. return true;
  39. }
  40. }
Success #stdin #stdout 0.15s 321344KB
stdin
1     1     2  hhh hhh
f f 232 dsd
stdout
3 11
1 3