Method using a double Parameter

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

Point  A = new Point();

short  a = 93,    b = 92;
int    i = 12,    j = 13;
long   x =  0,    y = 44;
double u = 13.45, v = 99.2;

A.move( i, b );   // OK --- b can be converted to int without loss 
A.move( a, x );   // NOT OK --- converting x to int may lose magnitude and precision 
A.move( u, b );   // NOT OK --- converting u to int may lose magnitude and precision 

Method using a double Parameter

The cos() method is a static method of the Math class. (Remember that a static method is a method that belongs to the definition of the class; you do not need an object to use it.) Here is how the method looks in the documentation for the Math class:

public static double cos( double num )

The method requires a parameter of type double. It evaluates to (returns) a double, the cosine of the parameter. The parameter is in radians (not degrees.) Here is it being used in a program:

class CosEg
{

  public static void main ( String arg[] )
  {
    double x = 0.0;
 
    System.out.println( "cos is:" + Math.cos( x ) );
  }
}

 

QUESTION 10:

Is the parameter in the method call the correct type?