Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.Scanner;
- public class Part2Test
- {
- public static void main(String[] args)throws InvalidStringException, IOException {
- File file = new File("test.txt");
- Scanner input = new Scanner(file);
- String regEx = ".*\\d+.*";
- String process;
- while(input.hasNext()){
- try {
- process = input.next();
- if(process.matches(regEx))
- throw new InvalidStringException(process, "Invalid Character Found!");
- if(process.length() > 20)
- throw new InvalidStringException(process, "Invalid! String excedes 20 characters", process.length());
- } //end try
- catch(Exception e) {
- System.out.println(e.getMessage());
- }//end catch
- }//end while
- input.close();
- }
- }
- ////////////////////////////////////////////////////////////////////////////////////
- public class InvalidStringException
- extends Exception {
- public InvalidStringException(String input, String err) {
- super(err);
- }
- public InvalidStringException(String input, String err, int size) {
- super(err);
- if(size > 20)
- throw new IllegalArgumentException();
- }
- }//end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement