import Foundation
print("Type two input: ")
if let input1 = readLine(), let input2 = readLine(), let value1 = Int(input1), let value2 = Int(input2) {
print("Sum=\(value1+value2)")
}
import Foundation
print("enter number one: ")
var sum = 0
if let num1 = Int(readLine()!) {
sum += num1
}
print("enter number two: ")
if let num2 = Int(readLine()!) {
sum += num2
}
print(sum)
import Foundation
guard let a = Int(readLine()!), let b = Int(readLine()!) else {
fatalError("expected a number got something else.")
}
print("mul = \(a * b)")
print("sum = \(a + b)")
3条答案
按热度按时间ibps3vxo1#
创建macos命令行工具项目。
第一步
第二步
dfuffjeb2#
首先创建一个sum变量,然后对于每个操作数,获取一个输入并将其转换为一个整数,您可以通过加法赋值运算符将其添加到sum中。
xmakbtuz3#