Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ACHTUNG! Ada 2 file disini!
- // CekNomor.java
- public class CekNomor {
- public CekNomor(String input) throws BukanNomorException {
- for(int i = 0; i < input.length(); i++) {
- if(input.charAt(i) < '0' || input.charAt(i) > '9') {
- throw new BukanNomorException("Index " + i + " bukan nomor!");
- }
- }
- }
- public static void main(String[] args) throws BukanNomorException {
- new CekNomor("12345"); // harusnya nggak ada Meldung
- new CekNomor("12a45"); // ada Meldung
- }
- }
- // BukanNomorException.java
- public class BukanNomorException extends Exception {
- public BukanNomorException(String message) {
- super(message);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement