fork(5) 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. String toTest = "";
  13. Scanner scan = new Scanner(System.in);
  14.  
  15. do{
  16. toTest += scan.nextLine();
  17. if (scan.hasNext()){
  18. toTest += "\n";
  19. continue;
  20. }
  21. }while (false);
  22.  
  23. int digitCount = 0, otherCount = 0;
  24. for (char c : toTest.toCharArray()){
  25. if (c >= '0' && c <= '9'){
  26. digitCount++;
  27. }
  28. else{
  29. otherCount++;
  30. }
  31. }
  32. System.out.println("Digits: " + digitCount + " Nondigits: " + otherCount);
  33.  
  34. int f1 = 1, f2 = 2;
  35.  
  36. while (true){
  37. if (f2 == digitCount && f1 == otherCount){
  38. System.out.println("Valid program");
  39. break;
  40. }
  41. int store = f2;
  42. f2 += f1;
  43. f1 = store;
  44.  
  45. if (f1 > digitCount){
  46. System.out.println("Invalid program");
  47. break;
  48. }
  49. }
  50. }
  51. }
Success #stdin #stdout 0.1s 380608KB
stdin
[72 101 108 108 111 32 119 111 114 108 100 33 {.}2*]''+
stdout
Digits: 34 Nondigits: 21
Valid program