斯威夫特山地车_斯威夫特| 两个数字相加的程序
斯威夫特山地車
In this program, we will have an idea - how two numbers can be added and displayed as the output on the screen?
在此程序中,我們將有一個想法- 如何將兩個數(shù)字相加并顯示為屏幕上的輸出 ?
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: 0Explanation:
說明:
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是一種數(shù)據(jù)類型,以num1作為變量,其值初始化為4 。 同樣, num2是具有相同數(shù)據(jù)類型的變量,其值初始化為6 。
Whereas, var ans includes same data type with ans as a variable where the result is stored.
而var ans包含與ans相同的數(shù)據(jù)類型,而ans作為存儲結(jié)果的變量。
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.
而結(jié)尾處的“程序以退出代碼0結(jié)尾”表示沒有其他程序要運行。
Semicolon ";" is must after every end of the command as similar in C/C++ etc.
分號“;” 在命令的每個結(jié)尾之后必須是,類似于C / C ++等。
翻譯自: https://www.includehelp.com/swift/addition-of-two-numbers.aspx
斯威夫特山地車
總結(jié)
以上是生活随笔為你收集整理的斯威夫特山地车_斯威夫特| 两个数字相加的程序的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一克冰多少钱啊?
- 下一篇: FIFA的完整形式是什么?