Thursday, 11 December 2014

// The "FunctionTypeMethod3" class.
public class FunctionTypeMethod3
{
    public static void main (String[] args)
    {
        //        EXAMPLE 3:
        //
        //         this function takes a real number and returns its square
        //
        //         function square ( number : real ) : real
        //
        //                 result number**2
        //
        //         end square
        //
        //         MAIN PROGRAM IN TURING:
        //         %  call the 'square' function 10 times to produce 10 squares
        //         for i : 1 .. 10
        //
        //                 put i : 2, square ( i ) : 4
        //
        //         end for                 %  the output is 10 squares of i

        System.out.println ("These are the 10 return values of the 'square' function: ");
        System.out.println ();
        for (int i = 1 ; i <= 10 ; i++)
        {
            // call the function'square' and pass i as a double number to it
            System.out.print ("i:\t");
            System.out.println (square (i));
        }
        System.out.println ();
        System.out.println ("This is the end of the 'square' function program!");
    } // main method


    // returns 10 squares of the given double number
    public static double square (double number)
    {
        // double numSquared = number * number;
        //return (double) (numSquared);
        return number * number;
    } // square method
   
} // FunctionTypeMethod3 class

No comments:

Post a Comment