forked from giakinh0823/java-programming-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPart1.java
More file actions
42 lines (39 loc) · 1.26 KB
/
Copy pathPart1.java
File metadata and controls
42 lines (39 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Workshop1;
import java.util.Scanner;
/**
*
* @author giaki
*/
public class Part1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter number of rows: ");
int rows = scanner.nextInt();
System.out.print("Enter number of cols: ");
int cols = scanner.nextInt();
int matrix[][] = new int[rows][cols];
System.out.println("Enter the matrix");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
System.out.print("matrix[" + i + "][" + j + "]= ");
matrix[i][j] = scanner.nextInt();
}
}
System.out.println("Matrix inputted: ");
int sum=0;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
System.out.print(matrix[i][j] + " ");
sum+=matrix[i][j];
}
System.out.println();
}
System.out.println("Sum: "+sum);
System.out.println("Average: " +(float)sum/(rows*cols));
}
}