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. System.out.println(numbers + " " + words);
  25. }
  26. }
  27.  
  28. private static boolean isInteger(String s) {
  29. try {
  30. Integer.parseInt(s);
  31. } catch(NumberFormatException e) {
  32. return false;
  33. } catch(NullPointerException e) {
  34. return false;
  35. }
  36. return true;
  37. }
  38. }
  39.  
Success #stdin #stdout 0.06s 711680KB
stdin
Romek ma 2 koty i 3 psy
2 plus 2 jest rowne 4
stdout
2 5
3 3