I must create a Java program that reads a .txt file and output a random phrase that the same read.
String line1,line2,line3,line4,line5,line6,line7;
int n;
Random rd = new Random();
try{
BufferedReader br = new BufferedReader(new FileReader("Phrases.txt"));
while(br.ready()){
line1 = br.readLine();
line2 = br.readLine();
line3 = br.readLine();
line4 = br.readLine();
line5 = br.readLine();
line6 = br.readLine();
line7 = br.readLine();
n = rd.nextInt(7);
String lines=line1+line2+line3+line4+line+line+line7;
for(int i=n;i<n;i++) {
System.out.println(lines);
}
}
br.close();
}catch(IOException ioe){
ioe.printStackTrace();
}
If I try to output any of the variables "line", it will print the phrase corresponding from the txt file.
Aucun commentaire:
Enregistrer un commentaire