forked from txs72/JavaTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCh08Q05.java
More file actions
executable file
·65 lines (63 loc) · 2.44 KB
/
Ch08Q05.java
File metadata and controls
executable file
·65 lines (63 loc) · 2.44 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* */ package ch08;
/* */
/* */ import java.util.Scanner;
/* */
/* */ public class Ch08Q05 {
/* */ public static void main(String[] args) {
/* 7 */ Scanner scanner = new Scanner(System.in);
/* 8 */ double[][] matrix1 = new double[3][3];
/* 9 */ double[][] matrix2 = new double[3][3];
/* 10 */ System.out.print("Enter matrix1: "); int i;
/* 11 */ for (i = 0; i < matrix1.length; i++) {
/* 12 */ for (int k = 0; k < (matrix1[i]).length; k++) {
/* 13 */ matrix1[i][k] = scanner.nextDouble();
/* */ }
/* */ }
/* 16 */ System.out.print("Enter matrix2: ");
/* 17 */ for (i = 0; i < matrix2.length; i++) {
/* 18 */ for (int k = 0; k < (matrix2[i]).length; k++) {
/* 19 */ matrix2[i][k] = scanner.nextDouble();
/* */ }
/* */ }
/* 22 */ double[][] result = addMatrix(matrix1, matrix2);
/* 23 */ System.out.println("The matrices are added as follows");
/* 24 */ for (int j = 0; j < result.length; j++) {
/* 25 */ int k; for (k = 0; k < (result[j]).length; k++) {
/* 26 */ System.out.printf("%3.0f", new Object[] { Double.valueOf(matrix1[j][k]) });
/* */ }
/* 28 */ if (j != 1) {
/* 29 */ System.out.print("\t\t");
/* */ } else {
/* */
/* 32 */ System.out.print("\t+\t");
/* */ }
/* 34 */ for (k = 0; k < (result[j]).length; k++) {
/* 35 */ System.out.printf("%3.0f", new Object[] { Double.valueOf(matrix2[j][k]) });
/* */ }
/* 37 */ if (j != 1) {
/* 38 */ System.out.print("\t\t");
/* */ } else {
/* */
/* 41 */ System.out.print("\t=\t");
/* */ }
/* 43 */ for (k = 0; k < (result[j]).length; k++) {
/* 44 */ System.out.printf("%3.0f", new Object[] { Double.valueOf(result[j][k]) });
/* */ }
/* 46 */ System.out.println();
/* */ }
/* */ }
/* */
/* */ public static double[][] addMatrix(double[][] a, double[][] b) {
/* 51 */ double[][] result = new double[3][3];
/* 52 */ for (int i = 0; i < a.length; i++) {
/* 53 */ for (int j = 0; j < (a[i]).length; j++) {
/* 54 */ result[i][j] = a[i][j] + b[i][j];
/* */ }
/* */ }
/* 57 */ return result;
/* */ }
/* */ }
/* Location: /Volumes/TXS.128G/hope useful/practice/2020.jar!/ch08/Ch08Q05.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/