/** 10/17/2018 */

public class PassByValue
  /** This class shows how parameters are similar to 
    * local variables in methods 
    */
{ 
 public static void main(String[]  args)
 {
  int num=1;
  double d=45.0;
  System.out.println("in main, num is " + num + " d is " + d);
  showSum(d, num*10);
  
  showSum(d, Math.abs(num)); // a parameter can be any expression
  
  // showSum(num, d); compiler error (wrong data type of param)
  // showSum(d);  compiler error (too few params)
  // pass by value means that d will NOT be affected by changes to x in method
  int x=550;  // this x is also not related to the method's x
  System.out.println("returned from method, d is " + d);
  
  System.out.println("sum of " + x + " and 467 is " + sum(x, 467));
  
  int sum=sum(123, 456); // assign the return value to a variable
  
// use sum in the rest of my program
 }
 /** method showSum simply adds two numbers and DISPLAYS the sum
   * @param  x  type double -- first number to add
   * @param  y  type int -- second number to add
   */
 public static void showSum(double x, int y) 
 {
   System.out.println("sum is: " + (x+y));
   x=0.0;
   System.out.println("x in method is now: " + x);
 }
 /** method sum simply adds two ints and RETURNS the sum
   * @param x  first number to add
   * @param y second number to add
   * @return the sum of x+y
   */
 public static int sum(int x, int y) 
 {
   int sum=x+y;
   return sum;  // return expression
   // alternative:   return x+y;
 }
} 

