VB求助:在一个五位数中有几个是7?尝试用If..Then..Else 嵌套Select..Case,但是比较复杂,求简单代码

2024年11月23日 04:50
有3个网友回答
网友(1):

a=34567
for i=1 to len(a)
if mid(a,i,1)=7 then n=n+1
next
print n

网友(2):

dim a,num
a="23767"
num=0
for i=1 to len(a)
if mid(a,i,1) mod 7=0 then
num=num+1
end if
next
msgbox "一共有"&num&"个7"

网友(3):

dim n as integer, m as integer, count as integer;
n = 12345
while n>10
m = n mod 10
if m = 7 then
count= count+1
end if
n = n \ 10
wend
if n = 7 then
count = count +1
end if
msgbox "有" & count & "个7“