Complete the code to define a method that prints a greeting.
public class HelloWorld { public static void [1]() { System.out.println("Hello, world!"); } public static void main(String[] args) { greet(); } }
The method name must be greet to match the call in main.
Complete the code to call the method that calculates the sum.
public class Calculator { public static int sum(int a, int b) { return a + b; } public static void main(String[] args) { int result = [1](5, 3); System.out.println(result); } }
The method to call is named sum, which adds two numbers.
Fix the error by completing the method call correctly.
public class Printer { public static void printMessage(String message) { System.out.println(message); } public static void main(String[] args) { [1]("Welcome!"); } }
The method to call is printMessage which takes a String argument.
Fill both blanks to create a method that returns the square of a number and call it.
public class MathUtils { public static int [1](int num) { return num [2] num; } public static void main(String[] args) { int sq = square(4); System.out.println(sq); } }
The method name is square and the multiplication operator * is used to calculate the square.
Fill all three blanks to create a method that checks if a number is even and call it.
public class NumberCheck { public static boolean [1](int n) { return n [2] 2 [3] 0; } public static void main(String[] args) { boolean result = isEven(10); System.out.println(result); } }
The method name is isEven. The modulus operator % checks the remainder, and == compares it to zero to confirm evenness.
