Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1.  
  2. {
  3. /**
  4. * Integer values being calculated upon
  5. * constructor call.
  6. */
  7.  
  8. public final int[] values = null;
  9.  
  10. /**
  11. * Transform a series of strings into integer values. In case
  12. * of invalid input, a corresponding error message will be written
  13. * to System.err and the current application will terminate by calling
  14. * {@link System#exit(int)}. Example: The array ["-1", "20", "three"]
  15. * contains two valid elements and the invalid element "three" which
  16. * cannot be converted to an integer value by virtue of
  17. * {@link Integer#parseInt(String)}.
  18. *
  19. * @param userInput A set of strings possibly representing integer values.
  20. */
  21.  
  22. public InputValidator(final String[] userInput)
  23. {
  24. try
  25. {
  26. for(int i = 0; i<userInput.length; i++)
  27. {
  28. int [] newIntArray = new int [userInput.length];
  29.  
  30. newIntArray [i] = Integer.parseInt(userInput[i]);
  31. }
  32. }
  33. catch(Exception e)
  34. {
  35. System.err.println("Cant convert to a real Integer");
  36. System.exit(0);
  37. }
  38. }
  39.  
  40. public void main (String [] args)
  41. {
  42. String anu[]={"3","2","5"};
  43. System.out.println(new InputValidator(anu));
  44.  
  45. String abnu[]={"three","2","5"};
  46. System.out.println(new InputValidator(abnu));
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement