Im a novice java learner, i have a little problem and i hope you guys can help me out. i have a Names.txt file that contains a huge amount of random names, each line has an appropriate name (expl: jhon Micheal Anthony etc...) I've been writing a function that randomly choses one of these names:
public static void RandomNameGenerator() throws FileNotFoundException
{
// the File.txt has organized names, meaning that each line contains a name
//the idea here is to get a random int take that number and find a name corresponding to that line number
int txtnumlines = 0; // how many lines the txt file has
Random random = new Random();
Scanner file = new Scanner(new File("Names.txt")); //loads the txt file
while (file.hasNext()) //counts the number of lines
{
file.nextLine();
txtnumlines += 1;
}
int randomintname = random.nextInt(txtnumlines);
// takes a random number, that number will be used to get the name from the txt line
String RandomName = "";
// I'm stuck here :(
}
the problem is i don't know how to continue, more specifically how to extract that name (let's say alex) using the random integers i have that represents a random line
hope my question was clear, Thank you for helping me out!