└── Drill00.java /Drill00.java: -------------------------------------------------------------------------------- 1 | public class Drill00 { 2 | 3 | /* 4 | * Return the given value incremented by one. 5 | * Note that there are no new lines with this function. 6 | * Brackets '{' and '}' decide how code is grouped, NOT 7 | * newlines and indentations. However, newlines and indentations 8 | * are important for readability. 9 | */ 10 | static int addOne(int val) { return val + 1; } 11 | 12 | /* 13 | * Return the maximum number between a and b. 14 | * In this function, an if statement is used. The condition provided 15 | * MUST be in parentheses 16 | */ 17 | static int max(int a, int b) { 18 | if (a > b) { 19 | return a; 20 | } else { 21 | return b; 22 | } 23 | } 24 | 25 | /* 26 | * Return the sum of a and b. 27 | */ 28 | static int sum2(int a, int b) { 29 | return a + b; 30 | } 31 | 32 | /* 33 | * Return true if the input value is between 10 and 20, inclusive. 34 | * Here, a boolean is being returned. In Python, this would have used the 35 | * 'and' keyword, but in Java, the same behavior can be performed by using 36 | * '&&'. The same can be done for the 'or' keyword, by using '||' 37 | */ 38 | static boolean range1(int a) { 39 | return (10 <= a && a <= 20); 40 | } 41 | 42 | /* 43 | * Return the absolute difference between two inputs. 44 | */ 45 | static int absDiff(int a, int b) { 46 | int diff = a - b; 47 | if (diff >= 0) { 48 | return diff; 49 | } else { 50 | return -diff; 51 | } 52 | } 53 | 54 | } 55 | --------------------------------------------------------------------------------