Asked by Raj

I have written a program to find the length of last word.Please tell me where I am wrong.

Dim a As String
Console.WriteLine("Enter a string")
a = Console.ReadLine

Dim lastWordLength As Integer
Dim beforeFirstNonEmptyChar As Integer
lastWordLength = 0
beforeFirstNonEmptyChar = True

If a.Length = 0 Then
Console.Write(lastWordLength)
End If

For i = a.Length - 1 To 0
If a(i) = " " Then
lastWordLength = lastWordLength + 1
beforeFirstNonEmptyChar = False
ElseIf beforeFirstNonEmptyChar Then
Exit For
End If
Next

Console.WriteLine(lastWordLength)
Console.ReadLine()
End Sub

Answers

Answered by oobleck
How do you know there's anything wrong? Have you run it to see whether it works? If not, what happens?
Answered by Raj
It doesn't work.
There are no AI answers yet. The ability to request AI answers is coming soon!

Related Questions