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,885 questions

51,811 answers

573 users

How to write a recursive function that counts digits of a number in VB.NET

1 Answer

0 votes
Imports System

Class CRecursiveCountDigits
    Public Shared Sub Main(ByVal args As String())
        Dim n As Integer = 12345
        Console.WriteLine(RecursiveCountDigits(n))
		
        n = 1234
        Console.WriteLine(RecursiveCountDigits(n))
		
        n = 123
        Console.WriteLine(RecursiveCountDigits(n))
		
        n = 1234567
        Console.WriteLine(RecursiveCountDigits(n))
    End Sub

    Public Shared Function RecursiveCountDigits(ByVal n As Integer) As Integer
        If n = 0 Then
            Return 0
        End If

        Return 1 + RecursiveCountDigits(n / 10)
    End Function
End Class



' run:
'
' 5
' 4
' 3
' 7
'

 



answered Apr 6, 2025 by avibootz
...