ios - 在 Ios 中,我需要接受三角形三边的长度作为输入,输出应指示三角形的类型
问题描述
我已经弄清楚了逻辑,但不知道如何编写代码。我不确定如何在 ios 上使用 if else 语句
If a==b && b==c Eqilateral If a==b or b==c or c==a Issoceles Else Scalene
解决方案
您可以使用 Set 来确定三角形类型
func triangleType(lengthSet: Set<Int>) -> String {
switch lengthSet.count {
case 1:
return "Equilateral"
case 2:
return "Isosceles"
default:
return "Scalene"
}
}
用法 :
self.triangleType(lengthSet: [2,2,3])
建议在调用函数之前评估您的输入计数;)
推荐阅读
- android - 如何使用 logb 将 android 数学函数转换为 swift
- python - 使用正则表达式替换文件中的子字符串和python
- python-3.x - kErrno 2 没有这样的文件或目录:'~/Users/root1/Coursera DeepLearning/Course2/dogs-vs-cats/train' - 但它存在
- c++ - C++ 输出 0 到 99998 并导致重复输出 2060
- javascript - 在没有 SDK 的情况下通过身份验证在 Google Pub/Sub 上推送消息
- winforms - 如何在 Windows 窗体 PowerShell 中显示鼠标悬停文本框工具提示?
- javascript - 来自 React UseContext 的数据在一段时间内未定义
- ruby-on-rails - 找不到 LibreOffice 或 OpenOffice 可执行文件
- r - 在 R 中返回一个嵌套的 JSON
- spring-boot - 使用spring boot 2.2.4更新到camel 3.0.0-RC3后,Camel在文本属性中找不到{{xxx}}