diff options
Diffstat (limited to 'java/03-count')
| -rw-r--r-- | java/03-count/.gitignore | 1 | ||||
| -rw-r--r-- | java/03-count/Count.java | 29 |
2 files changed, 30 insertions, 0 deletions
diff --git a/java/03-count/.gitignore b/java/03-count/.gitignore new file mode 100644 index 0000000..6b468b6 --- /dev/null +++ b/java/03-count/.gitignore @@ -0,0 +1 @@ +*.class diff --git a/java/03-count/Count.java b/java/03-count/Count.java new file mode 100644 index 0000000..cbc651e --- /dev/null +++ b/java/03-count/Count.java @@ -0,0 +1,29 @@ +public class Count { + public static void main(String[] args) { + if (args.length < 2) { + System.err.println("[ERROR] Type two integers as arguments."); + System.exit(1); + } + + int start = 0; + int end = 0; + + try { + start = Integer.parseInt(args[0]); + end = Integer.parseInt(args[1]); + } catch(NumberFormatException nfe) { + System.err.println("[ERROR] You didn't provide integer arguments."); + //System.err.println("Details: " + nfe.getMessage()); + System.exit(2); + } + + if(start > end) { + System.err.println("[ERROR] Start is greater than end."); + System.exit(3); + } + + for(int i = start; i <= end; i++) { + System.out.println(i); + } + } +} |
