Page 649

[ Team LiB ] 6 Object-oriented Programming 6.1 // Filename: Exercise1.java interface Function { public int evaluate(int arg); } class Half implements Function { public int evaluate(int arg) { return arg/2; } } public class Exercise1 { public static int[] applyFunctionToArray(int[] arrIn) { int length = arrIn.length; int[] arrOut = new int[length]; Function func = new Half(); for (int i=0; i< length; i++) arrOut[i] = func.evaluate(arrIn[i]); return arrOut; } } 6.2 // Filename: Exercise2.java interface Function { public int evaluate(int arg); } class Half implements Function { public int evaluate(int arg) { return arg/2; } } class Print implements Function { public int evaluate(int arg) { System.out.println(arg); return arg; } } public class Exercise2 { public static void main(String[] args) { // Create array with values 1 .. 10 int[] myArr = new int[10]; Page 651

Hint: If you are looking for high quality and reliable webspace provider to host and run your jsp hosting application check Sandzak jsp web hosting provider

Comments are closed.