How to output function calls in Java?

In Java, you can use the System.out.println() statement to output the result of a function call. The specific steps are as follows:

  1. Define a function in a Java program, for example:
public static int add(int a, int b) {
    return a + b;
}
  1. Call the function in the main function and output the result using System.out.println(), for example:
public static void main(String[] args) {
    int result = add(5, 3);
    System.out.println("调用add函数的结果是:" + result);
}
  1. Running the program will generate the following output:
调用add函数的结果是:8

By invoking a function and passing the result as a parameter to the System.out.println() statement, you can output the result of the function call in the program.

bannerAds