Advertisement
Guest User

Untitled

a guest
May 25th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. public class AlphabetTest {
  2.     public static String FSAAcceptableCharacters = "abc";
  3.    
  4.     public static void main(String[] args) {
  5.         String fileStr  = returnFileContent();
  6.        
  7.         System.out.println(fileStr); // making sure we read the right file
  8.  
  9.         try {
  10.             for(int i = 0; i < fileStr.length(); i++) {
  11.                 if(!Character.isLetter(fileStr.charAt(i))) { // alphabet test
  12.                     throw new Exception("Character '" + fileStr.charAt(i) + "' is not in the alphabet");
  13.                 }
  14.                
  15.                 String s = "";
  16.                
  17.                 if(FSAAcceptableCharacters.indexOf(s + fileStr.charAt(i)) == -1) {
  18.                     throw new Exception("Character '" + fileStr.charAt(i) + "' is not in the FSA accepting part of the alphabet");
  19.                 }
  20.             }
  21.            
  22.             System.out.println("No faulty character found"); // in case no faulty characters are found
  23.         } catch(Exception e) {
  24.             System.out.println(e.getMessage()); // show the error in the console
  25.         }
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement