-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calcolatrice.java
71 lines (65 loc) · 1.6 KB
/
Calcolatrice.java
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
66
67
68
69
70
71
public class Calcolatrice{
public double[] generaVettore(int L){
double[] vett = new double[L];
for (int i = 0; i < L; i++) {
vett[i] = Math.random() * 1000;
}
return vett;
}
public double[] sommaVettori(double[] a, double[] b){
if (a.length == b.length) {
double[] sum = new double[a.length];
for (int i = 0; i < a.length; i++) {
sum[i] = a[i] + b[i];
}
return sum;
}else{
return a;
}
}
public double[] concatenaVettori(double[] a, double[] b){
double[] c = new double[a.length + b.length];
for(int i = 0; i < a.length; i++){
c[i] = a[i];
}
for(int i = 0; i < b.length; i++){
c[i+a.length] = b[i];
}
return c;
}
public void stampaVettore(double[] a){
for(int i = 0; i < a.length; i++){
System.out.printf("%f\t", a[i]);
}
System.out.println("");
}
public double[][] generaMatrice(int R, int C){
double[][] mat = new double[R][C];
for(int i = 0; i < R; i++){
for(int j = 0; j < C; j++){
mat[i][j] = Math.random() * 100;
}
}
return mat;
}
public double[][] sommaMatrici(double[][] a, double[][] b){
if(a.length == b.length && a[0].length == b[0].length){
double[][] c = new double[a.length][a[0].length];
for(int i = 0; i < a.length; i++){
for(int j = 0; j < a[0].length; j++){
c[i][j] = a[i][j] + b[i][j];
}
}
return c;
}
return null;
}
public void stampaMatrice(double[][] m){
for(int i = 0; i < m.length; i++){
for(int j = 0; j < m[0].length; j++){
System.out.printf("%f\t", m[i][j]);
}
System.out.println("");
}
}
}