package com.heima.test;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class Test8 {
public static ArrayList<String> names = new ArrayList<>();
static{
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader("E:\\我的备课资源\\day01\\幸运抽奖\\persons1.txt"));
String name = null;
while((name = br.readLine()) != null) {
names.add(name);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void main(String[] args) {
System.out.println("这个哥们:"+names.get(getLucklyNum(78)) + "还在找工作,和买彩票");
}
public static int getLucklyNum(int num) {
//创建集合对象,添加元素
ArrayList<Integer> list = new ArrayList<>();
for (int i = 1; i <= num; i++) {
list.add(i);//1-8
}
//开始高新就业
int count = 1 ;
for (int i = 0; list.size()!= 1; i++)
if(i==list.size()) {
//归零
i = 0;
}
//开始就业
if(count % 3==0) {
System.out.println("恭喜恭喜!" + names.get(list.get(i)) +"高薪就业啦.!!20k");
list.remove(i--);
}
count++;
}
return list.get(0);
}
}
|
|