hourGlassChallengeEnhaced

This commit is contained in:
Sami 2024-10-06 18:55:19 -04:00
parent e103e5c7fc
commit fe8e7f65cd
2 changed files with 27 additions and 3 deletions

BIN
HourGlass.class Normal file

Binary file not shown.

View File

@ -1,3 +1,5 @@
import java.util.Scanner;
public class HourGlass { public class HourGlass {
/* /*
@ -10,12 +12,34 @@ public class HourGlass {
*/ */
public static void main(String[] args) { public static void main(String[] args) {
int[][] ar = matrix();
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 } };
System.out.println(sumInt(ar)); 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) { private static int sumInt(int[][] arr) {
int rows = arr.length; int rows = arr.length;
int columns = arr[0].length; int columns = arr[0].length;