cthlnlmd:
**だから私は私のロジッククイズのためのランダムな質問をしなければならないと私はここに書かれたコードを持っています。私はちょうどそれを学び始め、それは私には少し慣れていないので、私はkotlinを始めたので、私は、Javaの構文が何であるかを知りません。ここでは、コードは次のようになります**
Random r;
String [] quest = {"Which alphabet will be 14th to the left of 8th alphabet from the right in the following series of letters?" +
"A O B P C Q D R E S F T G U H V I W J X K Y L Z M N.", "Hritik is taller than Salman who is shorter than Sanjay. Akshay is taller than " +
"Shahrukh but shorter than Salman. Sanjay is shorter than Hritik. Who is the tallest?" , "Lali and Anju are a married couple. Tunu and Munu " +
"are brothers. Tunu is the brother of Lali. How is Munu related to Anju?", "How many sets of two letters have as many letters " +
"between them as in the English alphabetical order in the word ‘WRISTWATCH’."};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_easy);
Button question = findViewById(R.id.btnQuestion);
final TextView ask = findViewById(R.id.txtAsk);
r = new Random();
question.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ask.setText(quest[r.nextInt(quest.length)]);
}
});
}
アービンド・クマールのAvinash:
次のように実行します。
Random r = new Random();
String [] quest = {"Which alphabet will be 14th to the left of 8th alphabet from the right in the following series of letters?" +
"A O B P C Q D R E S F T G U H V I W J X K Y L Z M N.", "Hritik is taller than Salman who is shorter than Sanjay. Akshay is taller than " +
"Shahrukh but shorter than Salman. Sanjay is shorter than Hritik. Who is the tallest?" , "Lali and Anju are a married couple. Tunu and Munu " +
"are brothers. Tunu is the brother of Lali. How is Munu related to Anju?", "How many sets of two letters have as many letters " +
"between them as in the English alphabetical order in the word ‘WRISTWATCH’."};
boolean [] usedIndices = new boolean[quest.length];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_easy);
Button question = findViewById(R.id.btnQuestion);
final TextView ask = findViewById(R.id.txtAsk);
question.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int indextoBeUsed;
do {
indextoBeUsed = r.nextInt(quest.length);
} while (usedIndices[indextoBeUsed]);
usedIndices[indextoBeUsed] = true;
ask.setText(quest[indextoBeUsed]);
}
});
}
解決策は非常に単純です。任意の疑いの場合にはコメントをお気軽に。