Workshop #2: Exceptions: Learning Outcomes
Workshop #2: Exceptions: Learning Outcomes
Learning Outcomes:
Upon successful completion of this workshop, you will have demonstrated the abilities
to:
Requirements:
Part1: [5 points]
Write a Java program to accept a number and print out it. If the number is below 1 then a
message “the number is invalid” is printed out. Using do..while to input again, try-catch block to
handle errors.
1
Part 2: [5 points]
Write a Java program to accept a string and print out it. If the string does not match SExxx(x is
digit) then a message “the string is invalid” is printed out. Using do..while to input again.
Hint: In library class String, you should use the method matches() to do this, use try-
catch block and use throws to handle errors.
Background: In this workshop, you will use the pattern string( also called regular expression,
see more What is a Regular Expression? - Definition from Techopedia). You should read the
document to complete the exercise.
2
Task 1: use try-catch
At the row 9, use rules of the regular expression to create a pattern string “SExxx”, x is digit
3
4