Archive for the 'hrvatski' Category

[ Team LiB ] Page 652

Monday, February 5th, 2007

[ Team LiB ] Page 652
Hint: If you are looking for good and high quality web space to host and run your java application check Vision java web hosting services

[ Team LiB ] Page 652

Monday, February 5th, 2007

[ Team LiB ] 7 Nested Classes and Interfaces 7.1 // Filename: Exercise3.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 Exercise3 { /* Inner class that applies the function, prints the value, and returns the result. */ static class PrintFunc extends Print { PrintFunc(Function f) { func = f; } Function func; public int evaluate(int arg) { return super.evaluate(func.evaluate(arg)); } } // Inner class that just returns the argument unchanged. /* Use this when you want a PrintFunc object to printthe argument as-is. */ static class NoOpFunc implements Function { public int evaluate(int arg) { return arg; } } public static void main(String[] args) { // Create array with values 1 .. 10 int[] myArr = new int[10]; for (int i=0; i<10;) myArr[i] = ++i; // Print array without modificationapplyFunctionToArray(myArr, new PrintFunc(new Page 653
Hint: If you are looking for good and high quality web space to host and run your java application check Vision java web hosting services

[ Team LiB ] Page 652

Monday, February 5th, 2007

[ Team LiB ] Page 654
Hint: If you are looking for good and high quality web space to host and run your java application check Vision java web hosting services

Page 649

Monday, February 5th, 2007

[ 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

Page 649

Monday, February 5th, 2007

Page 649

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

Page 649

Monday, February 5th, 2007

[ Team LiB ] Page 650

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

[ Team LiB ] Page 646

Sunday, February 4th, 2007

Page 648
Hint: If you are looking for good and high quality web space to host and run your java application check Vision java web hosting services

[ Team LiB ] Page 646

Sunday, February 4th, 2007

[ Team LiB ] Page 646
Hint: If you are looking for good and high quality web space to host and run your java application check Vision java web hosting services

[ Team LiB ] Page 646

Sunday, February 4th, 2007

[ Team LiB ] 5 Control Flow, Exception Handling, and Assertions 5.1 Finding primes using for-loops. // Filename: ForPrimes.java public class ForPrimes { final static int MAX = 100; public static void main(String[] args) { numbers: for (int num = 1; num < MAX; num++) { int divLim = (int) Math.sqrt(num); for (int div = 2; div <= divLim; div++) if ((num % div) == 0) continue numbers; System.out.println(num); } } } Finding primes using while-loops. // Filename: WhilePrimes.java public class WhilePrimes { final static int MAX = 100; public static void main(String[] args) { int num = 1; numbers: while (num < MAX) { int number = num++; int divLim = (int) Math.sqrt(number); int div = 2; while (div <= divLim) if ((number % div++) == 0) continue numbers; System.out.println(number); } } } 5.2 /** A PowerPlant with a reactor core. */ public class PowerPlant { /** Each power plant has a reactor core. This has packageaccessibility so that the Control class which is definedin the same package can access it. */ Reactor core; /** Create and initialize the PowerPlant with a reactor core. Page 647
Hint: If you are looking for good and high quality web space to host and run your java application check Vision java web hosting services

[ Team LiB ] 3 Operators and Assignments

Sunday, February 4th, 2007

[ Team LiB ] 3 Operators and Assignments 3.1 The following program will compile and run without errors: // Filename: Sunlight.java public class Sunlight { public static void main(String[] args) { // Distance from sun (150 million kilometers) /* The max value for int is 2147483647, so using int here will work. */ int kmFromSun = 150000000; // Again, using int for this value is OK. int lightSpeed = 299792458; // Meters per second // Convert distance to meters. /* The result of this equation will not fit in an int. Let’s use a long instead. We need to ensure that the values that are multiplied really are multiplied using long data types, not multiplied as int data types and later converted to long. The L suffix on the 1000L integer literal ensures this. The value of kmFromSun will implicitly be converted from int to long to match the data type of the other factor. The conversion can be done implicitly by the compiler since the conversion represents a widening of the data type. */ long mFromSun = kmFromSun * 1000L; /* We know that the result value will fit in an int, but the compiler does not. We use an explicit cast to convince the compiler. The conversion must be specified explicitly, since the conversion represents a narrowing of the data type. */ int seconds = (int) (mFromSun / lightSpeed); System.out.print(”Light will use “); printTime(seconds); System.out.println(” to travel from the sun to the earth.”); } /* We leave this method alone. */ public static void printTime(int sec) { int min = sec / 60; sec = sec - (min*60); System.out.print(min + ” minute(s) and ” + sec + ” Page 643
Note: If you are looking for best hosting provider to host and run your tomcat application check Astra tomcat hosting services