2013-01-25 23 views
1

我正在提出問題和答案。我的問題是隨機產生的,但問題再次重複。如何不能再次獲得整數數組

即時使用txt文件作爲我的數據庫當int數組隨機生成我的持有人得到什麼是我的數據庫中的字符串行。應該是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(); 
      } 


} 
+3

STIL尚不清楚me.please闡述更 –

+0

先生納倫德拉感謝,我的問題是方法。當我點擊提交按鈕確認答案是否正確時,如果答案正確,問題方法將再次調用以再次生成問題。問題是我刪除的int數組將返回..請幫助我先生。你想發佈我的代碼嗎? –

回答

0

你有沒有嘗試下面的代碼解決重複問題的問題: -

Collections.shuffle(Arrays.asList(number)); 
+0

我會把收藏? –

+0

之前隨機函數 – duggu

+0

它隨機再次先生。你可以幫我調試嗎?:( –