Array index out of bound how ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Array index out of bound how ?

public static String sort(String s1) { char[] ch=s1.toCharArray(); for(int i=0;i<ch.length;i++) { for(int j=i+1;j<ch.length;i++) { if(ch[i]>ch[j]) { char temp=ch[i]; ch[i]=ch[j]; ch[j]=temp; } } } return new String(ch); } public static void main(String[] args) { String s1=new String("MoTHer In Law"); String s2=new String("HitLer Mother"); s1=sort(s1); s2=sort(s2); System.out.println(s1); System.out.println(s2); } }

16th Dec 2018, 1:12 PM
Mohib Ulla Khan
Mohib Ulla Khan - avatar
2 Answers
+ 3
Line 4: for(int i=0;I<ch.length-1 Line 6 for(int j=i+1;
16th Dec 2018, 1:25 PM
‎ ‏‏‎Anonymous Guy
+ 1
Got it insteaded of j++ i have written i++
16th Dec 2018, 1:26 PM
Mohib Ulla Khan
Mohib Ulla Khan - avatar