hourGlassChallengeEnhaced
This commit is contained in:
parent
e103e5c7fc
commit
fe8e7f65cd
BIN
HourGlass.class
Normal file
BIN
HourGlass.class
Normal file
Binary file not shown.
@ -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;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user