Intermediate Java
Jim White
Java Developer
class DoubleOrHalve {
public static void main(String[] args) {
int[] numbers = {23, 78, 2263, 552};
int[] newNumbers = doubleOddHalveEven(numbers); // Value is 46, 39, 4526, and 276
}
static int[] doubleOddHalveEven(int[] arr) {
for (int i = 0; i < arr.length; i++) { // Loop through the array
if (arr[i] % 2 == 0) {
arr[i] /= 2; // Halve even numbers
} else {
arr[i] *= 2; // Double odd numbers
}
}
return arr;
}
}
variable.method1().method2()
class CheckStrings {
public static void main(String[] args) {
String message = "Hello World!";
String input = "hello world!";
// Convert message to lower case, then compare with input
System.out.println(message.toLowerCase().equals(input));
}
}
true
➡ Makes code easier to understand, update, and maintain
Intermediate Java