Find the final co | Java implementation of the above approach ; Function to print the final position of the point after traversing through the given directions ; Traversing through the given directions ; If its north or south the point will move left or right ; If its west or east the point will move upwards or downwards ; Returning the final position ; Driver Code
import java . util . * ; class GFG { static void finalCoordinates ( int SX , int SY , char [ ] D ) { for ( int i = 0 ; i < D . length ; i ++ ) { if ( D [ i ] == ' N ' ) SY += 1 ; else if ( D [ i ] == ' S ' ) SY -= 1 ; else if ( D [ i ] == ' E ' ) SX += 1 ; else SX -= 1 ; } String ans = ' ( ' + String . valueOf ( SX ) + ' , ' + String . valueOf ( SY ) + ' ) ' ; System . out . print ( ans ) ; } public static void main ( String [ ] args ) { int SX = 2 , SY = 2 ; String D = " NSSE " ; finalCoordinates ( SX , SY , D . toCharArray ( ) ) ; } }