Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Passing {
- public static void main(String[] abs){
- int[][] m = getArray();
- System.out.printf("Sum of Array is: %d\n", +sum(m));
- }
- public static int[][] getArray(){
- System.out.println("Enter 2D array's values:-");
- Scanner in = new Scanner(System.in);
- int[][] m = new int[2][2];
- for(int i=0; i<2;i++){
- for(int j=0;j<2; j++) {
- m[i][j] = in.nextInt();
- }
- }
- return m;
- }
- public static int sum(int[][] m) {
- int total = 0;
- for(int i=0; i<2; i++) {
- for(int j=0; j<2; j++) {
- total = total+m[i][j];
- }
- }
- return total;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement