Professional Documents
Culture Documents
Lab Manual 1st Week
Lab Manual 1st Week
Lab Manual 1st Week
Methods – Week 1
Objectives:
To define and call void methods with formal parameters and with actual
parameters (i.e., arguments).
To define and call methods with a return value.
Examples:
Example01. Write Java program to define and call void myMethod() function.
myMethod() function prints a message “I just got executed!”:
Output:
I just got called and executed!
Example03. Write Java program to define and call myMethod(int firstNumber, int
secondNumber) function with a return value, where myMethod(int firstNumber,
int secondNumber) function returns the sum of firstNumber and secondNumber
parameters:
Output :
10
Exercises:
Write a class that contains the following two methods:
public static double footToMeter(double foot) /** Convert from feet to meters
*/
public static double meterToFoot(double meter) /** Convert from meters to feet */
Where the formula for the conversion is 1 meter = 0.305 * foot, and 1 foot = 3.279 * meter.
Consider the following values feets (1.0, 2.0, 3.0) and meters (20.0, 21.0, 22.0):