Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.regex.*;
- public class QuizCheck
- {
- /**
- Checks whether a string of quiz answers is valid. It must
- contain an answer A, B, C, or D for each expected answer, or an
- X to indicate that no answer was provided.
- @param input the answer string
- @param questions the number of questions in the string
- @return true if the string was valid, false otherwise
- */
- public static boolean checkInputs(String input, int questions)
- {
- if(input.length() != questions){return false;}
- if(input.length() != 0)
- {
- for(int i = 0; i < input.length(); i++)
- {
- switch(input.charAt(i))
- {
- case 'A':
- break;
- case 'B':
- break;
- case 'C':
- break;
- case 'D':
- break;
- case 'X':
- break;
- default:
- return false;
- }
- }
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement