Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,914 questions

51,847 answers

573 users

How to find the most frequent word in an array of strings with VB.NET

1 Answer

0 votes
Imports System

Public Class Program
    Public Shared Function mostFrequentWord(ByVal words As String()) As String
        Dim frequency As Integer = 0
        Dim size As Integer = words.Length
        Dim frequent_word As String = ""

        For i As Integer = 0 To size - 1
            Dim count As Integer = 1

            For j As Integer = i + 1 To size - 1
                If words(j).Equals(words(i)) Then
                    count += 1
                End If
            Next

            If count >= frequency Then
                frequent_word = words(i)
                frequency = count
            End If
        Next

        Return frequent_word
    End Function

    Public Shared Sub Main(ByVal args As String())
        Dim arr As String() = New String() {"java", "c++", "c", "c#", "c", "go", "php", "java", "java", "c", "python", "php", "c"}

        Dim frequent_word As String = mostFrequentWord(arr)

        Console.WriteLine(frequent_word)
    End Sub
End Class



' run:
'
' c
'

 



answered Jan 1, 2024 by avibootz

Related questions

...