Below is my code I'm expecting the output as "afbgchde" and not "abcdefgh" but ending up with out of index error, Hope there is a better way to get this..Please help..!!
String str1 = "abcde";
//char[] a = str1.toCharArray();
//System.out.println(a);
String str2 = "fgh";
char[] b = str2.toCharArray();
//System.out.println(b);
int i,j=0;
try
{
for(i=0;i<str1.length();i++)
{
char c = str1.charAt(i);
System.out.print(c);
if(j==i)
{
char d = str2.charAt(j);
System.out.print(d);
j++;
}
}
}
catch(Exception e)
{
System.out.println(e);
}