aboutsummaryrefslogtreecommitdiff
path: root/challenge-117/abigail/java/ch-1.java
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-117/abigail/java/ch-1.java')
-rw-r--r--challenge-117/abigail/java/ch-1.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/challenge-117/abigail/java/ch-1.java b/challenge-117/abigail/java/ch-1.java
new file mode 100644
index 0000000000..6a03391c2e
--- /dev/null
+++ b/challenge-117/abigail/java/ch-1.java
@@ -0,0 +1,43 @@
+//
+// See ../README.md
+//
+
+//
+// Run as: ln ch-1.java ch1.java; javac ch1.java; java ch1 < input-file
+//
+
+import java.util.*;
+
+public class ch1 {
+ public static void main (String [] args) {
+ Scanner scanner = new Scanner (System . in);
+ int sum = 0;
+ int SUM_15 = 120;
+ try {
+ while (true) {
+ String line = scanner . nextLine ();
+ //
+ // Googling suggest Java has a gazillion methods to
+ // convert string to integers -- and they all crap
+ // out if the string starts with a number, and has
+ // anything trailing. None of them actually similate atoi.
+ //
+ // So, handrolling it is!
+ //
+ int i, n = 0;
+ for (i = 0; i < line . length (); i ++) {
+ if (line . charAt (i) < "0" . charAt (0) ||
+ line . charAt (i) > "9" . charAt (0)) {
+ break;
+ }
+ n *= 10;
+ n += line . charAt (i) - "0" . charAt (0);
+ }
+ sum += n;
+ }
+ }
+ catch (Exception e) {
+ System . out . println (SUM_15 - sum);
+ }
+ }
+}