Count minimum moves required to convert A to B | Java program for the above approach ; Function to find minimum number of moves to obtained B from A ; Stores the minimum number of moves ; Absolute difference ; K is in range [ 0 , 10 ] ; Print the required moves ; Driver Code
import java . io . * ; class GFG { static void convertBfromA ( int a , int b ) { int moves = 0 ; int x = Math . abs ( a - b ) ; for ( int i = 10 ; i > 0 ; i -- ) { moves += x / i ; x = x % i ; } System . out . print ( moves + " ▁ " ) ; } public static void main ( String [ ] args ) { int A = 188 , B = 4 ; convertBfromA ( A , B ) ; } }