+ 1

Why it show exception???

In my question i want to find the list of boys and girls by using his/her sex code https://code.sololearn.com/c9O5AB1vXQ3e/?ref=app Donna [A^dr3w] Dan Walker Gaurav Agrawal ‎ ‏‏‎Sreejith 

5th Nov 2018, 4:06 PM
Harsh Agrawal
Harsh Agrawal - avatar
8 Answers
+ 2
//Harsh Agrawal Something like this String b[] = new String[n]; String g[] = new String[n]; . . . . int cnt1 = 0, cnt2 = 0; for(int i=0;i<nm.length-1;i++){ if(sc[i].equalsIgnoreCase('b')) { b [cnt1] = nm[i]; cnt1 ++; } else if(sc[i].equalsIgnoreCase('g')){ g [cnt2] = nm[i]; cnt2 ++; } else continue; } //cnt1 -> counter for boys //cnt2 -> counter for girls //equalIgnoreCase -> ignores case
7th Nov 2018, 2:22 AM
‎ ‏‏‎Anonymous Guy
+ 3
Hi after looking at your code I don't think you will ever get it to work as you want. Take a look at my code and consider using a linked list. I have used scanner class as I don't like buffer reader it just looks so clumsy https://code.sololearn.com/c1cKZ6EQ30K0/?ref=app Hope this gives you some new ideas
5th Nov 2018, 7:03 PM
[A^dr3w]
[A^dr3w] - avatar
+ 2
In third for you are using j to iterate. So i suppose you want to do it j++ not i++.
5th Nov 2018, 4:21 PM
Anya
Anya - avatar
+ 2
‎ ‏‏‎Sreejith  can u give me whole link Nd my question is i want to store seperate name of boys and girls according to sex code by using two different array
6th Nov 2018, 3:06 AM
Harsh Agrawal
Harsh Agrawal - avatar
+ 2
‎ ‏‏‎Sreejith  thnxzzz i got it but u cant believe i was thinking the same logic dat u applied but i did not try to solve it!!!!
8th Nov 2018, 3:14 PM
Harsh Agrawal
Harsh Agrawal - avatar
+ 1
declare string b and g at the beginning and append name to b and g instead of resetting it every time. Something like this g+=name +' ' b+=name +' ' This won't need a loop to display items
6th Nov 2018, 2:13 AM
‎ ‏‏‎Anonymous Guy
+ 1
‎ ‏‏‎Sreejith  So how wll i display girls and boys
8th Nov 2018, 4:54 AM
Harsh Agrawal
Harsh Agrawal - avatar
+ 1
//Harsh Agrawal : System.out.print("Boys: "); for(int i=0; i<b.length; i++) System.out.print(b[i] + " "); System.out.print("Girls: "); for(int i=0; i<g.length; i++) System.out.print(g[i] + " ");
8th Nov 2018, 3:08 PM
‎ ‏‏‎Anonymous Guy