Convert the number from International system to Indian system | Java program to convert the number from International system to Indian system ; Function to convert a number represented in International numeric system to Indian numeric system . ; Find the length of the sbInput ; Removing all the separators ( , ) from the sbInput ; Reverse the sbInput ; Declaring the output ; Process the sbInput ; Add a separator ( , ) after the third number ; Then add a separator ( , ) after every second number ; Reverse the output ; Return the output string back to the main function ; Driver code
import java . util . * ; class GFG { static String convert ( String input ) { StringBuilder sbInput = new StringBuilder ( input ) ; int len = sbInput . length ( ) ; for ( int i = 0 ; i < len ; ) { if ( sbInput . charAt ( i ) == ' , ' ) { sbInput . deleteCharAt ( i ) ; len -- ; i -- ; } else if ( sbInput . charAt ( i ) == ' ▁ ' ) { sbInput . deleteCharAt ( i ) ; len -- ; i -- ; } else { i ++ ; } } StringBuilder sbInputReverse = sbInput . reverse ( ) ; StringBuilder output = new StringBuilder ( ) ; for ( int i = 0 ; i < len ; i ++ ) { if ( i == 2 ) { output . append ( sbInputReverse . charAt ( i ) ) ; output . append ( " ▁ , " ) ; } else if ( i > 2 && i % 2 == 0 && i + 1 < len ) { output . append ( sbInputReverse . charAt ( i ) ) ; output . append ( " ▁ , " ) ; } else { output . append ( sbInputReverse . charAt ( i ) ) ; } } StringBuilder reverseOutput = output . reverse ( ) ; return reverseOutput . toString ( ) ; } public static void main ( String [ ] args ) { String input1 = "123 , ▁ 456 , ▁ 789" ; String input2 = "90 , ▁ 050 , ▁ 000 , ▁ 000" ; System . out . println ( convert ( input1 ) ) ; System . out . println ( convert ( input2 ) ) ; } }