From fe8e7f65cde9e2027bb3744d0a91c89bf362a29b Mon Sep 17 00:00:00 2001 From: Sami Date: Sun, 6 Oct 2024 18:55:19 -0400 Subject: [PATCH] hourGlassChallengeEnhaced --- HourGlass.class | Bin 0 -> 1816 bytes HourGlass.java | 30 +++++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 HourGlass.class diff --git a/HourGlass.class b/HourGlass.class new file mode 100644 index 0000000000000000000000000000000000000000..401a3e9459c2a3758ff8e890726f1adca88220ac GIT binary patch literal 1816 zcmaJ>O>Y}j6g@BYcpP_{k2X%454WaGsO>g!n}ihd1=J;tY0?i|Qc9@k#CbH+jAty* zxNTMlsS+zTuz>|a3JW$Ypo_FBQY02^Sg~Wpk{!RGstD)JxQ(k+jAXz2-n;j_bI-l+ z{r>OcZ2$$_NT3A~9Z>@sVgenv%{yk^Hl17fODnf!*%ydSTaM+=3Pdv5r3B(=)sZl; z4~9VNyj!oGw@uHZU&Zum);$3&lU-gewxSK~Iyww=;=l{Qr47%Q72>&d!Y3DkBP}<7 zxn?H_nkiy}({W@?kxUzS1xE#1EIRM9DLU2qE}Ikvl|n-ThceFzH@jq);y5ml zyKGC-lWFPrvX=JOWP0>mdNB|tEp1uhx|d#&wtII{rIA%Ryi7~V^ugsVEuuLeo9Zrb%CKhIlYXk zj%9(v|L@A{80N*>6XzqMz9?9H#Q1-nvlK_cQOiAq_?d>lJpa`;5J4-7c$c_6Tp!27-Mb2>fO0$LBKT zNDw&5>JGER@+5qUbWbzkQOYn5kM;)FK4rct^*%&**c?oKOz=~QCz$xhPuP literal 0 HcmV?d00001 diff --git a/HourGlass.java b/HourGlass.java index cdf5ddc..d67dc15 100644 --- a/HourGlass.java +++ b/HourGlass.java @@ -1,3 +1,5 @@ +import java.util.Scanner; + public class HourGlass { /* @@ -10,12 +12,34 @@ public class HourGlass { */ public static void main(String[] args) { - - int[][] ar = { { 1, 1, 1, 0, 0, 0 }, { 0, 1, 0, 0, 0, 0 }, { 1, 1, 1, 0, 0, 0 }, { 0, 0, 2, 4, 4, 0 }, - { 0, 0, 0, 2, 0, 0 }, { 0, 0, 1, 2, 4, 0 } }; + int[][] ar = matrix(); System.out.println(sumInt(ar)); } + private static int[][] matrix() { + Scanner scanner = new Scanner(System.in); + System.out.println("Please enter the 2D Matrix elements below:"); + System.out.println("Numbers of rows: "); + int rows = scanner.nextInt(); + System.out.println("Numbers of Columns: "); + int columns = scanner.nextInt(); + int[][] ar = new int[rows][columns]; + for (int i = 0; i < rows; i++) { + for (int j = 0; j < columns; j++) { + ar[i][j] = scanner.nextInt(); + } + System.out.println(); + } + for (int i = 0; i < rows; i++) { + for (int j = 0; j < columns; j++) { + System.out.print(ar[i][j] + "\t"); + } + System.out.println(); + } + scanner.close(); + return ar; + } + private static int sumInt(int[][] arr) { int rows = arr.length; int columns = arr[0].length;