Skip to content

Instantly share code, notes, and snippets.

@simplyniceweb
Last active October 3, 2017 18:39
Show Gist options
  • Save simplyniceweb/7c225b5ce578ef9069807a79dcc2f4d0 to your computer and use it in GitHub Desktop.
Save simplyniceweb/7c225b5ce578ef9069807a79dcc2f4d0 to your computer and use it in GitHub Desktop.
public void setRandomOptions()
{
String[] answers = {};
String[] options = {"PH", "USA", "NK", "SK"};
Integer opt = 0;
while (2 > opt) {
String randomOption = options[new Random().nextInt(options.length)];
// page eto working
/*
if (opt == 0) {
b2.setText(randomOption);
} else if (opt == 1) {
b3.setText(randomOption);
}
opt++;
*/
// eto d working pero walang error
if (!indexExists(answers, opt)) {
answers[opt] = randomOption;
opt++;
}
}
b2.setText(answers[0]);
b3.setText(answers[1]);
}
public boolean indexExists(String[] array,int index){
if(array!=null && index >= 0 && index < array.length)
return true;
else
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment