【Swift 60秒】20 - Arithmetic operators_豪冷啊
0x00 Lesson
Now you know all the basic types in Swift, we can start to put them together using operators. Operators are those little mathematical symbols like +
and -
, and Swift has a huge range of them.
Here are a couple of test variables for us to work with:
let firstScore = 12
let secondScore = 4
We can add and subtract using +
and -
:
let total = firstScore + secondScore
let difference = firstScore - secondScore
And we can multiply and divide using *
and /
:
let product = firstScore * secondScore
let divided = firstScore / secondScore
Swift has a special operator for calculating remainders after division: %
. It calculates how many times one number can fit inside another. then sends back the value that’s left over.
For example, we set secondScore to 4, so if we say 13 %
secondScore we’ll get back one, because 4 fits into 13 three times with remainder one:
let remainder = 13 % secondScore
0x01 Tips
the %
operator calculates division remainder
0x02 我的小作品
欢迎体验我的作品之一:小汉字-XHanzi
汉字书写入门,常用汉字 3800 个
App Store
搜索即可~
相关文章
- MyBatis Plus 的 Service 保存或更新数据_知识的搬运工旺仔_mybatisplus 保存或者更新
- 【TypeScript】中接口的详细介绍_林有酒
- css平移_该编程了_css平移
- MySQL连接命令_饿饿好饿_mysql连接命令
- MySQL性能指标TPS\QPS\IOPS如何压测?_IT邦德_mysql tps 测试
- vue自定义日历小组件_彭启滔_vue自定义日历组件
- Java初识(零基础起步)_ailigei_java新手
- MySQL超详细安装教程 手把手教你安装MySQL到使用MySQL 最简单的MySQL安装方式,这种方式装,卸载也简单_模糊化的_安装mysql的步骤和方法
- 【JavaScript】一文了解JS原型与原型链_亦世凡华、
- 基于springboot+vue+爬虫实现电影推荐系统_编程指南针
- 13.Spring security权限管理_EdSheeran?_springsecurity角色权限管理
- flex:1代表什么_不爱吃糖的程序媛_flex:1代表什么
- mysql进阶优化篇04??深入JOIN语句的底层原理_半旧518
- 常见前端面试题整理(带答案)_KloveD_前端面试题
- Appium1.22.3下载安装与配置_crayonJJ_appium下载安装
- 给你 2 万条数据,怎么快速导入到 MySQL?_time?Friend_快速导入mysql