/* Craig Persiko
Area.java
example program using method, for CS 111A
*/
import java.util.Scanner;
public class Area
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
double w, h, a;
System.out.print("Enter width: ");
w = s.nextDouble();
System.out.print("Enter height: ");
h = s.nextDouble();
a = area(w,h);
System.out.println("Area is: " + a);
}
/* area method: calculates and returns the area of
a rectangle with the given dimensions.
*/
static double area(double width, double height)
{
double result;
result = width * height;
return result;
}
}
/* Sample Output:
-bash-3.2$ java Area
Enter width: 5
Enter height: 7
Area is: 35.0
-bash-3.2$ java Area
Enter width: 1.5
Enter height: 30
Area is: 45.0
-bash-3.2$
*/
syntax highlighted by Code2HTML, v. 0.9