Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to call the method greet.
Java
public class Main { public static void greet() { System.out.println("Hello!"); } public static void main(String[] args) { [1]; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the parentheses when calling the method.
Trying to call the method with System.greet() which is incorrect here.
✗ Incorrect
To call a method in Java, you use its name followed by parentheses, like greet().
2fill in blank
mediumComplete the code to call the method add with arguments 5 and 3.
Java
public class Calculator { public static int add(int a, int b) { return a + b; } public static void main(String[] args) { int result = [1]; System.out.println(result); } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets or curly braces instead of parentheses.
Omitting parentheses around the arguments.
✗ Incorrect
To call a method with arguments, use the method name followed by parentheses enclosing the arguments separated by commas.
3fill in blank
hardFix the error in calling the method printMessage.
Java
public class Messenger { public static void printMessage(String msg) { System.out.println(msg); } public static void main(String[] args) { [1]; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using spaces instead of parentheses for arguments.
Using square or curly brackets instead of parentheses.
Not quoting the string argument.
✗ Incorrect
Method calls require parentheses around arguments. Use printMessage("Hello World") to pass the string argument.
4fill in blank
hardFill both blanks to call the method multiply with arguments 4 and 7 and store the result.
Java
public class MathOps { public static int multiply(int x, int y) { return x * y; } public static void main(String[] args) { int product = [1]; System.out.println([2]); } }
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping arguments in the method call.
Printing the method call instead of the stored variable.
✗ Incorrect
Call multiply(4, 7) to get the product, then print the variable product.
5fill in blank
hardFill all three blanks to call concat method with two strings and print the result.
Java
public class StringOps { public static String concat(String a, String b) { return a + b; } public static void main(String[] args) { String result = [1]; System.out.println([2]); System.out.println([3]); } }
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around string arguments.
Printing the method call instead of the stored variable.
Forgetting to print the final "Done" string.
✗ Incorrect
Call concat with two strings to get result, print result, then print "Done".
