Advertisement
Guest User

L10Methods.java

a guest
May 24th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. public class L10Methods{
  2.  
  3.  
  4.    public static void main(String[] args){
  5.       average(7, 23);
  6.       System.out.println( f(1.0) );
  7.       double fOf2 = f( 2.0 );
  8.       System.out.println( fOf2 );
  9.       for(double i = 1.0; i <= 10.0; i++) System.out.println( f(i) );
  10.    }
  11.    
  12.       //a method that returns the output of a function f
  13.    // x -> f -> f(x) aka y
  14.    // the function f is 3x + 5
  15.    public static double f( double x ){
  16.       double fx = 3 * x + 5;
  17.       return fx;
  18.    }
  19.    
  20.    //a method that calculates the average of two nums
  21.    //method takes in two values and prints the average
  22.    public static void average(double num1, double num2){
  23.       System.out.println( ( num1 + num2 ) / 2 );
  24.    }
  25.    
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement