+ 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Â
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
+ 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
+ 2
In third for you are using j to iterate. So i suppose you want to do it j++ not i++.
+ 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
+ 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!!!!
+ 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
+ 1
â âââSreejith So how wll i display girls and boys
+ 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] + " ");