1. 程式人生 > >最簡單逢7殺人遊戲java程式碼

最簡單逢7殺人遊戲java程式碼

package Tuesday;

import
java.util.ArrayList;

/**
 * Created by Administrator on 2016/8/31.
 */
public class Game {
   
public static void main(String[]args) {
        ArrayList<Integer> persons=
new ArrayList<Integer>();
        for
(int i = 1; i <= 100; i++) {
            persons.add(i)
;
       

}
       
int count= 0;
       
//逢7殺人,不斷地迴圈殺人
        while (persons.size()> 1) {
           
for (int i = 0; i < persons.size(); i++) {
               
//叫號計數
               
count++;
                if
(count % 7 == 0) {
                    System.
out.println(persons.remove(i) + "被殺了");
                   
//確保每一個人會被編號
                   
i--;
               
}
            }
        }
        System.
out.println(persons.get(0)+"活下來的人");
   
}
}