Find N Arithmetic Means between A and B | java program to illustrate n arithmetic mean between A and B ; insert function for calculating the means ; Finding the value of d Common difference ; for finding N the Arithmetic mean between A and B ; Driver code
import java . io . * ; import java . lang . * ; import java . util . * ; public class GFG { static void printAMeans ( int A , int B , int N ) { float d = ( float ) ( B - A ) / ( N + 1 ) ; for ( int i = 1 ; i <= N ; i ++ ) System . out . print ( ( A + i * d ) + " ▁ " ) ; } public static void main ( String args [ ] ) { int A = 20 , B = 32 , N = 5 ; printAMeans ( A , B , N ) ; } }