dimanche 17 avril 2016

to write out a random name

i've 8 names in my file and every single row has only one name. i'm trying to write out one of name with random. I've written some codes but i do not know how i'll continue.(I'm trying to solve that problem without using array because we did not learn yet). My list has those names;

patrica
natascha
lena
sara
rosa
kate
funny
ying

and i want to write out with system.out.println only one name with random

Here is my code

BufferedReader inputCurrent = new BufferedReader(new FileReader("aText.txt"));

    String str;
    int rowcounter =0;
    int mixNum =0;
    String strMixNum=null;
    while((str = inputCurrent.readLine())!= null){
        rowcounter++; 
        mixNum = rnd.nextInt(rowcounter)+1;
        //strMixNum = ""+strMixNum;

        String str2;
        while((str2 = inputCurrent.readLine())!= null){
            // i dont know what i s shall write here
            System.out.println(str2);
        }
    }

    inputCurrent.close();




Aucun commentaire:

Enregistrer un commentaire