CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ

Control

Control Statements
Static methods

The basic syntax for coding a static method

{public|private} static returnType methodName([parameterList])
{
    statements
}

A static method with no parameters or return type

private static void printWelcomeMessage()
{
    System.out.println("Hello New User");    // This could be a lengthy message
}

A static method with three parameters that returns a double value

public static double calculateFutureValue(
double monthlyInvestment, double monthlyInterestRate,
int months)
{
    double futureValue = 0.0;
    for (int i = 1; i <= months; i++)
    {
        futureValue = (futureValue + monthlyInvestment)
            * (1 + monthlyInterestRate);
    }
    return futureValue;
}
Previous | Static methods | Code | Call | Application