?c Z E ) ?3? P¨ZE )7y??¨ZE ) ?3ZE× ) a MZE`¥à Q ) ?.BUI ? ?c Z E ) ?3? P¨ZE )7y??¨ZE ) ?3ZE× ) a MZE`¥à Q ) ?.BUI ?   e?y??1 V??f ?bRí ′d b¥ZE?1 f ? Rí′ ?? 1WPJE¥ZE?1 V?b 4.1 7yZE ZEh B? f ?/ZEμ/ 2 ? e? Rí′ ?? ZE (? ? V ) { //ZE8 } ? e? ^ Vê¥ ·? ZE¥ ?? i Oá?Ir  ? ??¨?ZEb 4.1 7yZE ZEh B? f ?/ZEμ/ 2 ? e? Rí′ ?? ZE (? ? V ) { //ZE8 } Rí′ ?? ^ZE 1Rí¥′¥ ? ??b ?TZE? Rí′5Rí ? ?11o3 voidb 4.1 7yZE ZEh B? f ?/ZEμ/ 2 ? e? Rí′ ?? ZE (? ? V ) { //ZE8 } ZE V[μB?? ? V? ZE¥?S?1? T? ?b? ZE$?¨ H? T? ?¨M  ? 9D?tM  ? ?1 L=? ?b? ? ^ Vê ¥b 4.1 7yZE ZEh B? f ?/ZEμ/ 2 ? e? Rí′ ?? ZE (? ? V ) { //ZE8 } ZE8 ?B??lZES I 1¥? "?bμRí′ ¥ZE1 pμ1o3 return 7Rí′ ??1 void¥ZE5 V[ àμb ?TRí′ ? ?1 void¥ZE? P¨ return 5¨ ???ZEb 4.1 7yZE public static int max(int num1, int num2) { if (num1 > num2) return num1; else return num2; } ? e? ? e? Rí′ ?? Rí′ ?? ZE ZE ? ? ? ? ZEh Z Z E E 8 8 Rí′ Rí′ 4.2 ?¨ZE 7yZE H1?lZE ^? I 1¥b 1 P¨ZEA??¨?¨ ?b ?¨ZEμ ?o? ? ?TZERíB?′ZE¥?¨Yèü?T ) ?B?′b ? int larger = max(3, 4); ? ?TZERí voidZE¥?¨A? ^BH? b ? System.out.printlin(“Welcome to Java”); 4.2 ?¨ZE Example 4.1 ? k maxZE ?? è0 U8"7y??¨ maxZEb TestMax Run TestMax 4.2 ?¨ZE public static void main(String[] args) { int num1 = 5; int num2 = 2; int num3 = max(num1, num2); System.out.println("The maximum between " + num1 + " and " + num2 + " is " + num3); } static int max(int num1, int num2) { if (num1 > num2) return num1; else return num2; } class TestMax { } 4.3 ? ?.? void nPrintln(String message, int n) { for (int i=0; i<n; i++) System.out.println(message); } ZE¥ˉ ? ^ ?) ?? ?¥ ? ?b ?¨ZE H314 L?A?DZE ? ??¥??Q?M]'? ? ¨? ? ¥b ? nPrintln(“Hello”, 3); ? ??′.? ?¨{? ?¥ZE H L?¥′ˉ??Z E??1?′.?bí ?ZE?¥? ?8 "M?ZE?¥ L?? s?Yb Example 4.2 ? k?′.? '??7yB? ?M oD¥ZEb TestPassByValue Run TestPassByValue è0 a ü swap(n1, n2) swap(num1, num2) num1 num2 1 2 n1 n2 1 2 n1 n2 2 2 temp 1 3?ZE swap ?′.? è0 a ü swap(n1, n2) swap(num1, num2) num1 num2 1 2 n1 n2 1 2 n1 n2 2 2 temp 1 3?ZE swap ?¨ swapZEa num1 ˉ1 1 num2 ˉ1 2 e ì ¥′ àμy1?¨ swapZ E7?Db L?s ¥ ? ?? num1? num2¥i% bWb n1? n2¥?M?? Y num1? num2¥ = ?b ?′.? 4.4 ×ZE )ZE× ^ Java LC ?¥B?Z Tb ) è 4.1maxZEo ?¨? int? ? b ?TX1 ? ??? ??¥Kv ? ;$3 %÷E ^7 y 6B?{μ?]? ?¥] ZEb ? double max(double num1, double num2) { if (num1 > num2) return num1; else return num2; } 4.4 ×ZE è 4.1maxZEo ?¨? int? ? b ?T X1? ??? ??¥Kv ? ;$3 % ÷E ^7y 6B?{μ?]? ?¥] ZEb ? double max(double num1, double num2) { if (num1 > num2) return num1; else return num2; } ??ZE ?M] ?μ?] ? ?? T$?1ZE× method overloadingb?¨Z E H Java?"d ?? ZE 2 ü %??¨ '?ZEb 4.4 ×ZE Example 4.3 × maxZE ' è7y  ??ZE OZE ?M]  1 pKv? ?  2 pKv ?ú ?  3 p ?? ?ú ??Kv¥ ? TestMethodOverloading Run Class ?T max(2, 2.5)|?¨ '?ZE ;$ 4.5 ZE` ) ZE` ^üZE¥?¨] LCs ?b ) ???ZE ?? LC¥ f ?/¨?9 V[ P¨Z Eb ?T1?MZE¥ LCo1??MZE 2 ü 4ó¨?¥??ü?? s?Yb¨ ? aZE¥ LCü^??(0-?b ZE8 ZE 2 ü ?(0 Vê¥ { ? Vê¥Rí′ 4.6 Math ? ) Math ?c 3?' ?D ? ?31¥Z Eb )c¥ doubleè  – Math.PI – Math.E )c¥ZE – ??f ?ZE – · ?ZE –  eZE ? minamax aabsaround? random 4.6.1 ??f ?ZE )c/ ? ??f ?ZE –public static double sin(double a) –public static double cos(double a) –public static double tan(double a) –public static double acos(double a) –public static double asin(double a) –public static double atan(double a) )? ?V U[?9 ¥?b 1?? 4 /180 ?b 4.6.2 · ?f ?ZE )exp(double a) Rí e¥ aQZ e a  b )log(double a) Rí a¥1 ? ? ln(a)=log e (a) b )pow(double a, double b) Rí a¥ bQZ a b  b )sqrt(double a) Rí üZ? a  ? a? ?1μ ?b 4.6.3 Miscellaneous Methods )max(a, b)and min(a, b) Rí ? ?¥Kv′?Kl′b )abs(a) RíB? ?¥ '′b )random() Rí [0.0, 1.0) uW¥ double? ? ?b )round() Rí float′ 1 ? ?1 int′? double′ 1 ? ?1 long′b 4.6.4 P¨ Math ?¥ZE Example 4.4 9 ? ü (′?Sμ )' èI?? 3? 10? ? ? ) ?¨/ ? T9 ? ü (′?Sμb 1 1 2 ? ? = ∑ = n meanx deviation n i i n x mean n i i∑ = = 1 ComputeMeanDeviation Run 4.7 L èD Example 4.5 A U ° ? )' è7yB???A Uó? M¥ ° ?b ??4 U¨? { ? M? ?aA U? ¥ ° ?b )??ù5 { ??au? ° ?b ) ?u? ° ? VéB?s3??B? ?¥? ùa?? ?au?S5?u?  ??8b Design Diagram printCalendar(main) readInput printMonth getStartDay printMonthTitle printMonthBodygetNumOfDayIntMonth printMonthName isLeapYear Run PrintCalendar 4.8 ?B )?B ^B?c" <v? ?¥ ?Dà Q ^f ?°¤W¤?¨1-¥V?b )?BZEB?à μB? S ?¨??? Bb Example 4.6 9 ?¨e 0 = 1 n! = n * (n-1)!; n>0 79 ? n¥ZE factorial(0) = 1; factorial(n) = n*factorial(n-1); ComputeFactorial Run ?B?¨ MainZE factorial(4) factorial(4)=4* factorial(3) factorial(3)=3* factorial(2) factorial(2)=2* factorial(1) factorial(1)=1* factorial(0) factorial(0)=1 n = 4 Towers of Hanoi Example 4.7 3 %q v óù5 ) p3q v óù5b )??4 U¨? { ? ? ?i?¨?BZEA UM? ?0¥3b TowersOfHanoi Run Show ˉ5 ) P¨ZE¥ "¥ ^ I 1$8" a üB? ZE$8"?¨B?ZE$ ) I 1 ^ZE×$ V[?l ?] ? ? ? ???]¥ZE ?$ ) I 1 ^?BZE$ +? ^ I 1$ I?  )9 ?áo *  ? ? ?  V?B?l 1 fib(0) = 1; fib(1) =1; fib(n) = fib(n-2) + fib(n-1); n>=2 ComputeFibonacci Run Class