为什么在使用nextInt()时加0 [英] Why to add 0 while using nextInt()
本文介绍了为什么在使用nextInt()时加0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在跟着一个老师制作tic tac玩具游戏,以使其自动播放.
I am following an instructor creating tic tac toy game, to make it autoplay.
var r = Random()
val randInt = r.nextInt(emptyCell.size-0) + 0 // adding 0 here
为什么我们需要在这里加+0?
why do we need to add +0 here?
推荐答案
在这种情况下,您没有必要写下+ 0
的理由. nextInt
返回一个Int
,因此将0作为Int
添加到它绝对没有任何作用-不会改变类型或影响值-正如您所期望的那样.
There's no reason why you'd have to write down + 0
in that case. nextInt
returns an Int
, so adding 0 as an Int
to it does absolutely nothing - doesn't change the type or affect the value - as you'd expect.
可能是本教程中的错字.
Probably a typo in the tutorial.
这篇关于为什么在使用nextInt()时加0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文