Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void print(int[][] matrix){
- Scanner scan = new Scanner(System.in);
- for (int row = 0; row < matrix.length; row++) {
- for (int col = 0; col < matrix.length; col++) {
- System.out.printf("[%d] row [%d] col: ",row ,col);
- matrix[row][col] = scan.nextInt();
- }
- }
- }
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.print("Enter row and cols :");
- int rowAndColLength = scanner.nextInt();
- int[][] arr = new int[rowAndColLength][rowAndColLength];
- print(arr);
- System.out.println();
- for (int row = 0; row < arr.length; row++) {
- for (int col = 0; col < arr.length; col++) {
- System.out.print(arr[row][col] + " ");
- }
- System.out.println();
- }
- System.out.println();
- for (int row = 0; row < arr.length; row++) {
- for (int col = 0; col < arr.length; col++) {
- int sum = 0;
- if(col + 1 < arr.length){
- sum = sum + arr[row][col] + arr[row][col+1];
- System.out.println();
- System.out.printf("Sum --> row[%d]: col[%d] + col[%d] is: %d",row,col,col+1,sum);
- System.out.println();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement