aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-07-18 00:30:47 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-07-18 00:30:47 +0100
commit177c1a03addc30ad8e22bd13d680dc795d0eeb60 (patch)
treec53375dc97351ddc7e3d74bd806313d0c6f593b1
parent20a9f33f0ae2294e2009805f1087d156015a3dfb (diff)
downloadperlweeklychallenge-club-177c1a03addc30ad8e22bd13d680dc795d0eeb60.tar.gz
perlweeklychallenge-club-177c1a03addc30ad8e22bd13d680dc795d0eeb60.tar.bz2
perlweeklychallenge-club-177c1a03addc30ad8e22bd13d680dc795d0eeb60.zip
- Added guest contribution by Laurent Rosenfeld.
-rw-r--r--challenge-173/laurent-rosenfeld/java/ch-1.java23
1 files changed, 23 insertions, 0 deletions
diff --git a/challenge-173/laurent-rosenfeld/java/ch-1.java b/challenge-173/laurent-rosenfeld/java/ch-1.java
new file mode 100644
index 0000000000..5d3b1cd081
--- /dev/null
+++ b/challenge-173/laurent-rosenfeld/java/ch-1.java
@@ -0,0 +1,23 @@
+import java.lang.Math;
+
+public class EstheticNumber {
+ public static void main(String[] args) {
+ Integer[] tests = {5456, 120, 121, 23456, 2346, 7654567, 765467};
+ for (int i = 0; i <= 6; i++) {
+ if (is_esthetic(tests[i])) {
+ System.out.printf("%-9d is esthetic\n", tests[i]);
+ } else {
+ System.out.printf("%-9d is not esthetic\n", tests[i]);
+ }
+ }
+ }
+ public static boolean is_esthetic(int n) {
+ String s = Integer.toString(n);
+ for (int i = 1; i < s.length(); i++ ) {
+ if (Math.abs((int)(s.charAt(i)) - (int)(s.charAt(i-1))) != 1) {
+ return false;
+ }
+ }
+ return true;
+ }
+}