/** Examples of operations on primitive Java data types
**/
public class Example1 {
public static void main (String [] args ) {
Example1 instance = new Example1();
// Assumes an int value is given on the command line
int argval = Integer.parseInt(args[0]);
System.out.println("squared:" + instance.square(argval));
System.out.println("area:" + instance.areaOfCircle(argval));
}
// instance variable definitions, if any
// method definitions that pertain to actions that Something can be
// asked to do
public int square(int arg) {
int result;
// Add code here to compute arg * arg and save the result in
// the local variable result
return result;
}
public double areaOfCircle( int radius ) {
double result;
// Add code here to compute the area if a circle whose radius
// is given: area = Pi * (radius squared)
// Hint: Java defines a constant Math.PI
return result;
}
}
|