Print the String in X format/pattern in Java Programming
In this article we are going to see, how to print the given string in x format in Java programming. I am take following example to tell how its working. Input: 12345 Output: 1 5 2 4 3 2 4 1 5 To iterate the given string one by one, I am converting the String value to character array type. and then I am assigning the value [a.length()-1] to variable 'j' [i.e J=4]. Now I am using 'for loop' to iterate by setting value for 'i' [i.e I=0]. inside a loop again I am calling another 'for loop'. so that I can get each character array value [i.e charArray[0]=1,charArray[1]=2,etc] each time the value for 'i' is increase. Initially 'i' value 0 and 'j' value 4 for above given example input [i.e i=0 and j=4]. Inside the nested loop (i.e for(k=0;k<a.length();k++) ), I am checking 'i' value and 'k' value is equal. if it is equal then print charArray[k] (i.e charArray[0]) otherwise print...