Create a new string by alternately combining the characters of two halves of the string in reverse | Java program for creating a string by alternately combining the characters of two halves in reverse ; Function performing calculations ; Calculating the two halves of string s as first and second The final string p ; It joins the characters to final string in reverse order ; It joins the characters to final string in reverse order ; Driver method ; Calling function
import java . io . * ; class GFG { public static void solve ( String s ) { int l = s . length ( ) ; int x = l / 2 ; int y = l ; String p = " " ; while ( x > 0 && y > l / 2 ) { char ch = s . charAt ( x - 1 ) ; p += ch ; x -- ; ch = s . charAt ( y - 1 ) ; p += ch ; y -- ; } if ( y > l / 2 ) { char ch = s . charAt ( x - 1 ) ; p += ch ; y -- ; } System . out . println ( p ) ; } public static void main ( String args [ ] ) { String s = " sunshine " ; solve ( s ) ; } }