I am not completely sure what you are asking but I think you have two arrays of Strings one containing names of illnesses and the other containing the symptoms of each of those diseases. I am guessing that the symptoms in s
correspond to the illnesses in x
at the same index. So Diabetes's symptoms are Unexplained weight loss,Increase frequency of urination,Increase volume of urine,Increase thirst, Overweight.
So I think your question is how do you get the number of symptoms from that String and compare it to the number of symptoms from the other illnesses. (I don't have enough rep to comment so I might as well give a full answer to what I think your question is).
For this task you need to count the number of symptoms first. To do that I just counted the number of commas in the String and added one, this assumes that the symptoms are separated by commas and don't end with a comma, but it seems like that is the format.
int sympNum[] = new int[s.length];
for(int i=0;i<s.length;i++)
{
for(int j=0;j<s[i].length();j++)
{
if(s[i].charAt(j)==',')
sympNum[i]++;
}
sympNum[i]++;
}
Now that we know the number of each you want to sort the array and then print the illnesses accordingly. Well that is a little tricky because the array of the number of lengths only relates to the array of illnesses by the indexes. I made a new array of the symptom numbers sorted and then just compared that to the unsorted array which related back to original array of diseases because they have the same index.
int[] sorted = Arrays.copyOf(sympNum, sympNum.length);
Arrays.sort(sorted); //sorts the array into ascending order
for(int i=sorted.length-1;i>=0;i--) //you want descending so count backwards
{
int spot = 0;
while(sorted[i]!=sympNum[spot])
spot++;
System.out.println(x[spot]); //when they match it prints the illnesses that corresponds to that number of symptoms
sympNum[spot] = Integer.MAX_VALUE; //I did this so that if there are multiple diseases with the same number of illnesses one doesn't get printed multiple times
}
It would really be better to make the illnesses objects each with it's own array of Strings containing symptoms and also an int with the number of symptoms.
Next time please word your question more thoughtfully so we can figure out what you are asking. I hope that instead of just copying my code and turning this in you learn about object oriented programming and try your own version.
http://docs.oracle.com/javase/tutorial/java/javaOO/