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); } }
2 Respostas
+ 3
Line 4:
for(int i=0;I<ch.length-1
Line 6
for(int j=i+1;
+ 1
Got it insteaded of j++ i have written i++