Java – Android random number
•
Java
I generate a random card from the array And assign it. "
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); }
Solution
B is an int
Therefore, you need to rank the [b] array somewhere in the code
According to your code, you should probably read showcard1 Setbackgroundresource (rank Union [b]);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码