Find N Geometric Means between A and B | java program to illustrate n geometric mean between A and B ; insert function for calculating the means ; Finding the value of R Common ration ; for finding N the Geometric mean between A and B ; Driver code
import java . io . * ; import java . lang . * ; import java . util . * ; public class GFG { static void printGMeans ( int A , int B , int N ) { float R = ( float ) Math . pow ( ( float ) ( B / A ) , 1.0 / ( float ) ( N + 1 ) ) ; for ( int i = 1 ; i <= N ; i ++ ) System . out . print ( A * Math . pow ( R , i ) + " ▁ " ) ; } public static void main ( String args [ ] ) { int A = 3 , B = 81 , N = 2 ; printGMeans ( A , B , N ) ; } }