Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaapplication1;
- import java.util.Scanner;
- public class JavaApplication1 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int sum_row = 0;
- int row = 3;
- int column = 3;
- int[][] arr = new int[row][column];
- //Gets user input
- for (int i = 0; i < row; i++){
- for (int j = 0; j < column ; j++){
- System.out.println("arr[" + i + "][" + j + "] = ");
- arr[i][j] = sc.nextInt();
- }
- }
- System.out.println();
- //Outputs array
- for (int i = 0; i < row; i++){
- for (int j = 0; j < column ; j++){
- System.out.println("arr[" + i + "][" + j + "] = " + arr[i][j]);
- }
- }
- System.out.println();
- //Prints sum of row
- for (int i = 0; i < row; i++){
- for (int j = 0; j < column ; j++){
- sum_row += arr[i][j];
- }
- System.out.println("Sum row " + i +": " + sum_row);
- sum_row = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement