0
0
Javaprogramming~15 mins

Method calling in Java - Interactive Code Practice

Choose your learning style8 modes available
ads_clickPractice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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];
    }
}
🎯 Drag options to blanks, or click blank then click option
Agreet()
Bgreet
Ccall greet()
DSystem.greet()
Attempts:
3 left
2fill in blank
medium

Complete 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);
    }
}
🎯 Drag options to blanks, or click blank then click option
Aadd{5, 3}
Badd 5, 3
Cadd[5, 3]
Dadd(5, 3)
Attempts:
3 left
3fill in blank
hard

Fix 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];
    }
}
🎯 Drag options to blanks, or click blank then click option
AprintMessage{Hello World}
BprintMessage("Hello World")
CprintMessage['Hello World']
DprintMessage msg
Attempts:
3 left
4fill in blank
hard

Fill 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]);
    }
}
🎯 Drag options to blanks, or click blank then click option
Amultiply(4, 7)
Bmultiply(7, 4)
Cproduct
Dx * y
Attempts:
3 left
5fill in blank
hard

Fill 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]);
    }
}
🎯 Drag options to blanks, or click blank then click option
Aconcat("Hello, ", "World!")
Bresult
C"Done"
Dconcat("Hi", " there")
Attempts:
3 left