Please help me with the logic for finding the count of words in String Array. Without use of String methods would be a plus point.
The code I have been working on:
class Scratch
{
public static void main(String args[])
{
String[] str = { "sup", "aisu", "sup", "aisu", "sandy",
"sandu", "vijay", "gani", "sup", "sup", "gani", "sandu" };
int i = 0, j = 0, k = 0, count = 0;
System.out.println("The array size is" + str.length);
System.out.println("The array elements are");
for (i = 0; i < str.length; i++)
System.out.println(str[i]);
System.out.println("Comparison");
for (j = 0; j < str.length; j++)
{
for (k = 1; k < str.length - 1; k++)
{
if (str[j] == str[k])
{
count++;
break;
}
}
}
System.out.println("," + count);
}
}
Please note the logic should not contain Collections concept.
OUTPUT REQUIREMENT
Count of sup is : 4
Count of aisu is : 2
Count of sandy is : 1
Count of sandu is : 2
Count of vijay is : 1
Count of gani is : 2