import java.io.File;
import java.util.Scanner;
public class RandomMovie {
public int randomNumber() throws Exception{
File file = new File("movies.txt");
Scanner scanner = new Scanner(file);
int randomRange = 0;
int Random;
while(scanner.hasNextLine()){
String line = scanner.nextLine();
randomRange++;
}
Random = (int) ((Math.random() * randomRange) + 1);
/* Test randomRange
for (int i=Random; i<=25;Random = (int) ((Math.random() * randomRange) + 1)) {
System.out.println(Random);
}
*/
return Random;
}
public String randomMovie() throws Exception{
File file = new File("movies.txt");
Scanner scanner = new Scanner(file);
//Bring the Random Movie
int counter = 1;
String Movie;
while(scanner.hasNextLine() && counter == randomNumber()){
String finalLine = scanner.nextLine();
Movie = finalLine;
counter++;
}
return Movie;
}
}
The problem in the second function randomMovie() in return Movie;