CDE
This commit is contained in:
parent
518da4a923
commit
764da6cbbb
6144 changed files with 83610 additions and 11 deletions
20
Task/Dot-product/Java/dot-product.java
Normal file
20
Task/Dot-product/Java/dot-product.java
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
public class DotProduct {
|
||||
|
||||
public static void main(String[] args) {
|
||||
double[] a = {1, 3, -5};
|
||||
double[] b = {4, -2, -1};
|
||||
|
||||
System.out.println(dotProd(a,b));
|
||||
}
|
||||
|
||||
public static double dotProd(double[] a, double[] b){
|
||||
if(a.length != b.length){
|
||||
throw new IllegalArgumentException("The dimensions have to be equal!");
|
||||
}
|
||||
double sum = 0;
|
||||
for(int i = 0; i < a.length; i++){
|
||||
sum += a[i] * b[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue