0

我将我的excel文件导入Java。我现在正试图从我的数据中随机挑选 5 个人。我将如何去做...这是我到目前为止的代码。

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;

public class Rewards {

        public static void main(String[] args) throws FileNotFoundException, IOException {

        String fileName = "C:/Users/Jordan/Desktop/Project5.csv";
    try {
        BufferedReader br = new BufferedReader(new FileReader(fileName));
        String strLine = null;
        StringTokenizer st = null;
        int lineNumber = 0, tokenNumber = 0;

        while((fileName = br.readLine()) != null) {
            lineNumber++;
            String[] result = fileName.split(",");
            for (int x=0; x<result.length; x++) {
                System.out.println(result[x]);
             }
        }
    }

    catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
        }
}
4

1 回答 1

0

我将从一个Random实例开始。你怎么能在任何编程语言中伪随机地做任何事情?

于 2013-11-03T19:25:37.310 回答