+ 1
how to convert a string s="INDIABIX" to "IDNIAIBX"
4 Answers
+ 3
string s ="INDIABIX";
string temp;
temp[0] =s[1];
s[1]=s[2];
s[2]=temp[0];//now s is IDNIAIBX
take a look
http://uupload.ir/files/n5l_j.png
+ 1
See how "replace" can be used: http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#replace(java.lang.CharSequence,%20java.lang.CharSequence)
0
public class sm
{
public static void main(String[] args) {
String g="INDIABIX";
char[] s=g.toCharArray();
char temp;
temp=s[1];
s[1]=s[2];
s[2]=temp;
temp=s[5];
s[5]=s[6];
s[6]=temp;//IDNIAIBX
System.out.println(s);
}
}
- 1
it will change n to d only