From 7a083e3ad4201442badb8b6ff67f21cc2ec53469 Mon Sep 17 00:00:00 2001 From: E7-87-83 Date: Mon, 11 Apr 2022 02:18:14 +0800 Subject: correct filing --- challenge-159/cheok-yin-fung/java/Moebius.java | 79 ++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 challenge-159/cheok-yin-fung/java/Moebius.java (limited to 'challenge-159/cheok-yin-fung/java/Moebius.java') diff --git a/challenge-159/cheok-yin-fung/java/Moebius.java b/challenge-159/cheok-yin-fung/java/Moebius.java new file mode 100644 index 0000000000..b52e049ca8 --- /dev/null +++ b/challenge-159/cheok-yin-fung/java/Moebius.java @@ -0,0 +1,79 @@ +// The Weekly Challenge 159 +// Task 2 Moebius Function +// Usage: java Moebius N + +public class Moebius +{ + public static void main(String[] args) + { + int N = 1; + try { + N = Integer.parseInt(args[0]); + } catch (Exception e) { + System.err.print("Please use a positive integer "); + System.err.println("as your parameter."); + System.exit(0); + } + double[][] complex1 = new double[][] { {1, 0} , {0, 1} }; + double[][] complex2 = new double[][] { {0, 1} , {-1, 0} }; + System.out.println(Math.round(mu(N))); + } + + + public static double mu(int n) + { + double[][] sum = ithRootOfUnityModuloN(1, n); + LOOP: for (int i=2; i Date: Mon, 11 Apr 2022 18:04:43 +0800 Subject: Arithmetic Exception for an input parameter = 0 --- challenge-159/cheok-yin-fung/java/Moebius.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'challenge-159/cheok-yin-fung/java/Moebius.java') diff --git a/challenge-159/cheok-yin-fung/java/Moebius.java b/challenge-159/cheok-yin-fung/java/Moebius.java index b52e049ca8..f59c059631 100644 --- a/challenge-159/cheok-yin-fung/java/Moebius.java +++ b/challenge-159/cheok-yin-fung/java/Moebius.java @@ -9,6 +9,8 @@ public class Moebius int N = 1; try { N = Integer.parseInt(args[0]); + if (N==0) + throw new ArithmeticException(); } catch (Exception e) { System.err.print("Please use a positive integer "); System.err.println("as your parameter."); -- cgit From 141b4ca6ec4695386b56813dc58815c03b92c161 Mon Sep 17 00:00:00 2001 From: E7-87-83 Date: Mon, 11 Apr 2022 18:18:56 +0800 Subject: negative integers are also not allowed --- challenge-159/cheok-yin-fung/java/Moebius.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'challenge-159/cheok-yin-fung/java/Moebius.java') diff --git a/challenge-159/cheok-yin-fung/java/Moebius.java b/challenge-159/cheok-yin-fung/java/Moebius.java index f59c059631..fbd6b0af30 100644 --- a/challenge-159/cheok-yin-fung/java/Moebius.java +++ b/challenge-159/cheok-yin-fung/java/Moebius.java @@ -9,7 +9,7 @@ public class Moebius int N = 1; try { N = Integer.parseInt(args[0]); - if (N==0) + if (N<=0) throw new ArithmeticException(); } catch (Exception e) { System.err.print("Please use a positive integer "); -- cgit