First chapter of “Algorithm” is the fundamental of javaPRogramming language and a brief introduction to algorithms and data structure, including their concepts. some interesting problems and the basic implementations of them.
Code fragment
find the maximum of the array values
double max = a[0];for(int i = 0; i < a.length; i++) { if(a[i] > max) max = a[i];}
compute the average of the array values
double sum = 0;for(int i = 0; i < a.length; i++) { sum += a[i];}double average = sum / a.length;
copy to another array
double[] b = new double[a.length];for(int i = 0; i < a.length; i++) { b[i] = a[i];}
reverse the elements within an array
double tmp;for(int i = 0; i < a.length; i++) { tmp = a[i]; a[i] = a[a.length-1-i]; a[a.length-1-i] =tmp;}