Program for finding the Integral of a given function using Boole 's Rule | Java program to implement Boole 's Rule on the given function ; Function to return the value of f ( x ) for the given value of x ; Function to computes the integrand of y at the given intervals of x with step size h and the initial limit a and final limit b ; Number of intervals ; Computing the step size ; Substituing a = 0 , b = 4 and h = 1 ; Driver code
class GFG { static float y ( float x ) { return ( 1 / ( 1 + x ) ) ; } static float BooleRule ( float a , float b ) { int n = 4 ; int h ; h = ( int ) ( ( b - a ) / n ) ; float sum = 0 ; float bl = ( 7 * y ( a ) + 32 * y ( a + h ) + 12 * y ( a + 2 * h ) + 32 * y ( a + 3 * h ) + 7 * y ( a + 4 * h ) ) * 2 * h / 45 ; sum = sum + bl ; return sum ; } public static void main ( String [ ] args ) { System . out . printf ( ( " f ( x ) ▁ = ▁ % .4f " ) , BooleRule ( 0 , 4 ) ) ; } }