ONLY THE METHODS ARE NEEDED, NOT THE MAINS,..SO JUST THEMETHODS WILL BE ENOUGH a
ID: 3619043 • Letter: O
Question
ONLY THE METHODS ARE NEEDED, NOT THE MAINS,..SO JUST THEMETHODS WILL BE ENOUGH a) write a method static int inp(int [] v, int[] w) that returns the so-called inner product between arrays v andw. The inner product is defined as the sum of the products of theircorresponding entries, v[i]*w[i], over all i=0,1,..., v.length.E.g, for a={1,2,3} and b={5,1,-2} method inp(a,b) returns the value1*5+2*1+3*(-2)=5+2-6=1
b) write a method static int adif(int[] a, int[] b)
that returns the sum of the absolute values of differencesbetween corresponding entries of arrays a and b(which are of thesame length), a[i]-b[i] over all i=0,1,....,a.length. the absolutevalue in Java is determined with method Math.abc(). Eg, fora={1,2,3} and b={5,1,3} method adif(a,b) returns the value|1-5|+|2-1|+|3-3|=4+1+0=5
c) write a method
static double mean(int a, int b, int c, int d) that returns the average value of a, b, c, and d. E.g.,mean(3,9,5,2) returns the value (3+9+5+2)/4=4.75, and mean(2,4,5,5) returns the value(2+4+5+5)/4=4.0. static int dot(int [] a, int[] b)
ONLY THE METHODS ARE NEEDED NOT THE WHOLE PROGRAM,..PLEASE USESIMPLE CODE(IFS, FOR, WHILE,METHODS, ARRAYS)
ONLY THE METHODS ARE NEEDED, NOT THE MAINS,..SO JUST THEMETHODS WILL BE ENOUGH static int inp(int [] v, int[] w) that returns the so-called inner product between arrays v andw. The inner product is defined as the sum of the products of theircorresponding entries, v[i]*w[i], over all i=0,1,..., v.length.E.g, for a={1,2,3} and b={5,1,-2} method inp(a,b) returns the value1*5+2*1+3*(-2)=5+2-6=1
b) write a method static int adif(int[] a, int[] b)
that returns the sum of the absolute values of differencesbetween corresponding entries of arrays a and b(which are of thesame length), a[i]-b[i] over all i=0,1,....,a.length. the absolutevalue in Java is determined with method Math.abc(). Eg, fora={1,2,3} and b={5,1,3} method adif(a,b) returns the value|1-5|+|2-1|+|3-3|=4+1+0=5
c) write a method
static double mean(int a, int b, int c, int d) that returns the average value of a, b, c, and d. E.g.,mean(3,9,5,2) returns the value (3+9+5+2)/4=4.75, and mean(2,4,5,5) returns the value(2+4+5+5)/4=4.0.
static double mean(int a, int b, int c, int d) that returns the average value of a, b, c, and d. E.g.,mean(3,9,5,2) returns the value (3+9+5+2)/4=4.75, and mean(2,4,5,5) returns the value(2+4+5+5)/4=4.0. static int dot(int [] a, int[] b)
ONLY THE METHODS ARE NEEDED NOT THE WHOLE PROGRAM,..PLEASE USESIMPLE CODE(IFS, FOR, WHILE,METHODS, ARRAYS)
Explanation / Answer
please rate - thanks static int inp(int v[], int w[]) //assuming thelengths of v and w are the same {inti,sum=0; //adding so initialize to 0 (additiveidentity) for(i=0;iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.