斯威夫特山地车_斯威夫特| 两个数字相加的程序

斯威夫特山地车

In this program, we will have an idea - how two numbers can be added and displayed as the output on the screen?

在此程序中,我们将有一个想法- 如何将两个数字相加并显示为屏幕上的输出

Open XCode terminal and type the following program

打开XCode终端并键入以下程序

import Foundation 

var num1 = 4; 
var num2 = 6; 

var ans = Int(); 
ans = num1+num2; 

print("num1 + num2 = ",ans); 

Output

输出量

num1 + num2 = 10 
Program ended with exit code: 0 

Explanation:

说明:

  • import Foundation is a library which is used to access all the functions present that header file.

    import Foundation是一个库,用于访问该头文件中提供的所有功能。

  • var is a data type with num1 as a variable whose value is initialized as 4. Similarly, num2 is a variable with same data type whose value is initialized as 6.

    var是一种数据类型,以num1作为变量,其值初始化为4 。 同样, num2是具有相同数据类型的变量,其值初始化为6

  • Whereas, var ans includes same data type with ans as a variable where the result is stored.

    而var ans包含与ans相同的数据类型,而ans作为存储结果的变量。

  • print function prints the string with the answer on the output screen.

    打印功能在输出屏幕上打印带有答案的字符串。

  • Whereas, "program ended with exit code: 0" at the end shows that there are no further programs to be run.

    结尾处的“程序以退出代码0结尾”表示没有其他程序要运行。

  • Semicolon ";" is must after every end of the command as similar in C/C++ etc.

    分号“;” 在命令的每个结尾之后必须是,类似于C / C ++等。

翻译自: https://www.includehelp.com/swift/addition-of-two-numbers.aspx

斯威夫特山地车

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值