16. Equivalent Method Definitions Java Programming: From Problem Analysis to Program Design, 4e public static double larger( double x, double y) { double max; if (x >= y) max = x; else max = y; return max; }
21. Java Programming: From Problem Analysis to Program Design, 4e The int variable num contains the desired sum to be rolled
22.
23. Solution: isPalindrome Method Java Programming: From Problem Analysis to Program Design, 4e public static boolean isPalindrome(String str) { int len = str.length(); int i, j; j = len - 1; for (i = 0; i <= (len - 1) / 2; i++) { if (str.charAt(i) != str.charAt(j)) return false ; j--; } return true ; }
24.
25.
26. Solution: Largest Number Java Programming: From Problem Analysis to Program Design, 4e static Scanner console = new Scanner(System.in); public static void main(String[] args) { double num; double max; int count; System.out.println("Enter 10 numbers."); num = console.nextDouble(); max = num; for (count = 1; count < 10; count++) { num = console.nextDouble(); max = larger(max, num); } System.out.println("The largest number is " + max); }
27.
28.
29. Void Methods with Parameters: Syntax Java Programming: From Problem Analysis to Program Design, 4e
30. Void Methods with Parameters: Syntax (continued) Java Programming: From Problem Analysis to Program Design, 4e
31.
32.
33.
34. Reference Variables as Parameters: type String Java Programming: From Problem Analysis to Program Design, 4e
35. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 4e
36. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 4e
37. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 4e
38. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 4e String str = "Hello"; //Line 5
39. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 4e stringParameter(str); //Line 7
40. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 4e pStr = "Sunny Day"; //Line 14
41. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 4e Variables before the statement in Line 8 executes