Position after taking N steps to the right and left in an alternate manner | Java program to find the last coordinate where it ends his journey ; Function to return the last destination ; Driver Code
import java . util . * ; class solution { static int lastCoordinate ( int n , int a , int b ) { return ( ( n + 1 ) / 2 ) * a - ( n / 2 ) * b ; } public static void main ( String args [ ] ) { int n = 3 , a = 5 , b = 2 ; System . out . println ( lastCoordinate ( n , a , b ) ) ; } }