我想知道我可以如何匹配我的兩個數組,其猜測字母,它的一個小寫字母和4大寫字母的遊戲,我希望大寫字母之一應該是相同的小寫,所以我可以點擊匹配的信件! thnks的答案!一個字母猜謎遊戲的孩子android
package com.example.alfabetet;
import java.util.*;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.TextView;
public class AlfaSpelet extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.alfaspelet);
String gemen[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "å", "ä", "ö" };
String alfa[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "Å", "Ä", "Ö" };
TextView txt1 = (TextView) findViewById(R.id.textView2);
TextView txt2 = (TextView) findViewById(R.id.textView3);
TextView txt3 = (TextView) findViewById(R.id.textView4);
TextView txt4 = (TextView) findViewById(R.id.textView5);
TextView txt5 = (TextView) findViewById(R.id.textView6);
Random random = new Random();
int rnd1 = random.nextInt(alfa.length);
int rnd2 = random.nextInt(alfa.length);
int rnd3 = random.nextInt(alfa.length);
int rnd4 = random.nextInt(alfa.length);
int rnd5 = random.nextInt(gemen.length);
txt1.setText(alfa[rnd1]);
txt2.setText(alfa[rnd2]);
txt3.setText(alfa[rnd3]);
txt4.setText(alfa[rnd4]);
txt5.setText(gemen[rnd5]);`enter code here`
rnd5應該是一個從RND1到rnd4 ......使[] RND = INT新[4]提出的隨機數有則INT選擇INT =中隨機選擇0〜 3;然後選擇gemen [rnd [selected]] ...記住當你調用random.nextInt(alfa.length)時,你可以多次獲得相同的數字...所以也許更好的是它將洗牌int從0到alfa.length並取前4個元素 – Selvin