标签云

微信群

扫码加入我们

WeChat QR Code

Any tips why my random doesn't work? All i get in input are stacked lines from first to 11. I think it will be a small mistake but i can't figure it out :/package pl.mtgpackgenerator;import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.util.Random;public class Test {public static void main(String[] args) throws IOException {Random random = new Random();int randomInt = random.nextInt(59);FileReader fr = new FileReader("Common.txt");BufferedReader reader2 = new BufferedReader(fr);String line = reader2.readLine();for (int i = 0; i <= 10; i++) {line = reader2.readLine();System.out.println(line);}reader2.close();}}


Where are you using randomInt ?

2019年04月19日35分21秒

what you are trying achieve?

2019年04月19日35分21秒

And your loop is only reading the first 11 lines!

2019年04月18日35分21秒

Im trying to receive random eleven lines where in each line is text.

2019年04月19日35分21秒

with "receive random eleven lines" you mean read 11 lines starting from a random line in the file ?

2019年04月18日35分21秒

Thank you sir, ArrayList was the solution.

2019年04月19日35分21秒

How does the value in i affect which line is read?

2019年04月18日35分21秒