【发布时间】:2018-09-27 02:54:54
【问题描述】:
所以我正在尝试计算字符串中小写字母的数量。像这样:
intput: "hello world"
output: 10
这就是我所拥有的:
let lowers (str : string) : int =
let count = 0
for i=0 to (str.Length-1) do
if (Char.IsLower(str.[i])) then (count = count+1)
else count
printf "%i" count
但我不断收到此错误:
All branches of an 'if' expression must have the same type. This expression was expected to have type 'bool', but here has type 'int'.
我花了好几个小时试图解决这个问题,但一点进展也没有。我怎样才能打印出我拥有的计数值?它还说:
expecting an int but given a unit
请帮忙
【问题讨论】:
标签: count f# type-mismatch