Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- /**
- * Integer values being calculated upon
- * constructor call.
- */
- public final int[] values = null;
- /**
- * Transform a series of strings into integer values. In case
- * of invalid input, a corresponding error message will be written
- * to System.err and the current application will terminate by calling
- * {@link System#exit(int)}. Example: The array ["-1", "20", "three"]
- * contains two valid elements and the invalid element "three" which
- * cannot be converted to an integer value by virtue of
- * {@link Integer#parseInt(String)}.
- *
- * @param userInput A set of strings possibly representing integer values.
- */
- public InputValidator(final String[] userInput)
- {
- try
- {
- for(int i = 0; i<userInput.length; i++)
- {
- int [] newIntArray = new int [userInput.length];
- newIntArray [i] = Integer.parseInt(userInput[i]);
- }
- }
- catch(Exception e)
- {
- System.err.println("Cant convert to a real Integer");
- System.exit(0);
- }
- }
- public void main (String [] args)
- {
- String anu[]={"3","2","5"};
- System.out.println(new InputValidator(anu));
- String abnu[]={"three","2","5"};
- System.out.println(new InputValidator(abnu));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement