fork(2) download
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. class Ideone
  5. {
  6. public static int strToInt(String valor, int padrao)
  7. {
  8. try {
  9. return Integer.valueOf(valor);
  10. }
  11. return padrao;
  12. }
  13. }
  14.  
  15. public static void main (String[] args) throws java.lang.Exception
  16. {
  17. int valor1 = strToInt("2015", 2015);
  18. int valor2 = strToInt("20iiii5", 2015);
  19.  
  20. System.out.println(valor1); // 2015
  21. System.out.println(valor2); // 2015
  22. }
  23. }
Success #stdin #stdout 0.05s 711168KB
stdin
Standard input is empty
stdout
2015
2015