1

我在做问答。我的问题随机生成,但问题再次重复。

当 int 数组随机生成时,我使用 txt 文件作为我的数据库,我的持有者得到我数据库中的字符串行。应该是 int array = x 和 string line = y; {y==x}。我的问题是当我再次产生问题时,我应该怎么做伙计们?

             private void question() {


          InputStreamReader inputStream = new InputStreamReader
            (getResources().openRawResource(R.raw.question1));
            BufferedReader br = new BufferedReader(inputStream);

            ArrayList<Integer> ar= new ArrayList<Integer>();
            int[] number= {1,2,3,4,5,6,7,8,9,10};
            for (int i : number) {
                ar.add(i);


            }

            Random r = new Random();


            int select = r.nextInt(ar.size());
            int random = ar.get(select);
               ar.remove(select);               
            String theLine="";
            int lineCtr = 0;

            try {          

            while ((theLine = br.readLine()) != null)   {

            if (lineCtr == select) {    

        StringTokenizer st = new   StringTokenizer(theLine,",");
            while(st.hasMoreTokens())

        {   

            //reading and getting data from the database","
                         String a = st.nextToken();
                         String b = st.nextToken();
                         String c = st.nextToken();
                         String d = st.nextToken();
                         String e = st.nextToken();
                         String f = st.nextToken();

                         //button setText
                         question.setText(a);
                         ca.setText(f);
                         firstbutton.setText(e);
                         secondbutton.setText(d);
                         thirdbutton.setText(b);
                         fourthbutton.setText(c);
                     //assigning
                         firstholder =e;
                 secondholder =d;
                 thirdholder=b;
                 fourthholder =c;
                break;

                     }

                  }lineCtr++;

            }  


            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } 


}
4

1 回答 1

0

您是否尝试过以下代码来解决重复问题:-

Collections.shuffle(Arrays.asList(number));
于 2013-01-25T05:50:54.620 回答