aboutsummaryrefslogtreecommitdiff
path: root/challenge-323/deadmarshal/java
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-323/deadmarshal/java')
-rw-r--r--challenge-323/deadmarshal/java/Ch1.java16
-rw-r--r--challenge-323/deadmarshal/java/Ch2.java17
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-323/deadmarshal/java/Ch1.java b/challenge-323/deadmarshal/java/Ch1.java
new file mode 100644
index 0000000000..d83355c039
--- /dev/null
+++ b/challenge-323/deadmarshal/java/Ch1.java
@@ -0,0 +1,16 @@
+public class Ch1 {
+ public static void main(String[] args) {
+ System.out.println(increment_decrement(new String[]{"--x", "x++", "x++"}));
+ System.out.println(increment_decrement(new String[]{"x++", "++x", "x++"}));
+ System.out.println(increment_decrement(new String[]{"x++", "++x", "--x", "x--"}));
+ }
+
+ private static int increment_decrement(String[] arr) {
+ int x = 0;
+ for (String s : arr) {
+ if (s.contains("++")) x++;
+ else x--;
+ }
+ return x;
+ }
+}
diff --git a/challenge-323/deadmarshal/java/Ch2.java b/challenge-323/deadmarshal/java/Ch2.java
new file mode 100644
index 0000000000..b2208c1d23
--- /dev/null
+++ b/challenge-323/deadmarshal/java/Ch2.java
@@ -0,0 +1,17 @@
+public class Ch2 {
+ public static void main(String[] args) {
+ System.out.println(tax_amount(10, new int[][]{{3, 50}, {7, 10}, {12, 25}}));
+ System.out.println(tax_amount(2, new int[][]{{1, 0}, {4, 25}, {5, 50}}));
+ System.out.println(tax_amount(0, new int[][]{{2, 50}}));
+ }
+
+ private static double tax_amount(int income, int[][] taxes) {
+ int res = 0, prev = 0;
+ for (var e : taxes) {
+ res += Math.max(0, Math.min(income, e[0]) - prev) * e[1];
+ prev = e[0];
+ }
+ return res / 100.0;
+ }
+}
+