用vb编写程序for循环,让用户输入一个字符串,输出这个字符串中字母a和b出现
1个回答
展开全部
Dim in_str As String
Dim s1 As Integer, s2 As Integer
in_str = InputBox("请输入字符串")
For i = 1 To Len(in_str)
t$ = Mid$(in_str, i, 1)
If t$ = "a" Or t$ = "b" Then
Print t$
If t$ = "a" Then s1 = s1 + 1 Else s2 = s2 + 1
End If
Next i
Print "a=" & s1 & " b=" & s2
Dim s1 As Integer, s2 As Integer
in_str = InputBox("请输入字符串")
For i = 1 To Len(in_str)
t$ = Mid$(in_str, i, 1)
If t$ = "a" Or t$ = "b" Then
Print t$
If t$ = "a" Then s1 = s1 + 1 Else s2 = s2 + 1
End If
Next i
Print "a=" & s1 & " b=" & s2
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询