Android的随机数 [英] Android Random Number
本文介绍了Android的随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我为产生从Array单随机卡。和分配它。
下面是code..but其是否显示错误。
有什么问题?
公共无效兰特(){
串秩[] = {tclub1.png,tclub2.png,tclub3.png,tclub4.png,tclub5.png,tclub6.png,tclub7.png,tclub8 .PNG,tclub9.png,tclub10.png,tclub11.png,tclub12.png,tclub13.png}; 随机randInt =新的随机(); INT B = randInt.nextInt((rank.length));
showcard1.setBackgroundResource(二);
}
解决方案
b为一个int
所以你需要等级[B]数组在你的code某一点
根据您的code也许它应该阅读
showcard1.setBackgroundResource(排名[B]);
I m generating one random card from array. and assigning it.' Below is the code..but its is showing an error. What is the problem?
public void rand() {
String rank[]= {"tclub1.png", "tclub2.png", "tclub3.png", "tclub4.png", "tclub5.png", "tclub6.png", "tclub7.png", "tclub8.png", "tclub9.png", "tclub10.png","tclub11.png", "tclub12.png", "tclub13.png"};
Random randInt = new Random();
int b = randInt.nextInt((rank.length));
showcard1.setBackgroundResource(b);
}
解决方案
b is an int
so you need rank[b] the array at some point in your code
According to your code maybe it should read showcard1.setBackgroundResource(rank[b]);
这篇关于Android的随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文