How to call a method with parameters in Java?

To call a method with parameters in Java, do this: object.myMethod(param1, param2).

Here's how you do it:

public class Example {

  public void print(String text) {
    System.out.println(text);
  }

  public int add(int x, int y) {
    return x + y;
  }

  public int add(int x, int y, int z) {
    // calls own method twice
    return add(add(x, y), z);
  }
}

Example example = new Example();

// 1) Call a method with 1 parameter
// This will print: Hello World!
example.print("Hello World!");

// 2) Call a method with 2 parameters
int twoPlusThree = example.add(2, 3);
System.out.println(twoPlusThree); // 5

// 3) Call a method (that calls other methods) with 3 parameters
int twoPlusThreePlusFour = example.add(2, 3, 4);
System.out.println(twoPlusThreePlusFour); // 9

// 4) Call a static method
double twoSquared = Math.pow(2, 2);
System.out.println(twoSquared); // 4.0