This question already has an answer here:
- How do I compare strings in Java? 23 answers
I want use 2 random from a String list. Compare the 2 string and if they are same, re-use random.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
(...)
playerge= new String[] {"player1", "player2", "player3", "player4"};
(...)
}
public void GenerPlay_u(){
int idx = new Random().nextInt(playerge.length);
String player1_stock = (playerge[idx]);
String player2_stock = (playerge[idx]);
String text23 = player1_stock + " " + player2_stock;
Toast.makeText(phrasesgenerator_players.this,
text23, Toast.LENGTH_SHORT).show();
}
public void GenerPlay(){
GenerPlay_u();
if ((player1_stock) == (player2_stock)){
GenerPlay_u();
}
}
But my Toast tell me "player1 player1", or "player2 player2" or "player3 player3" "player4 player4. I didn't have 2 differents player.
Can you help me to resolve my problem ? Thank you
Aucun commentaire:
Enregistrer un commentaire