I have 3 text files named matrix.txt, matrix1.txt, matrix2.txt. I should get a different output since the text file will change every time the program runs. How to do? Appreciating your help.
This is what I was doing:
int min = 1;
int max = 2;
int randomNum = ThreadLocalRandom.current().nextInt(min, max + 1);
File file = new File("matrix" + randomNum + ".txt");
if(file.toString().equals("matrix1.txt")) {
System.out.println("Input filename:" + "matrix1.txt");
}
else if(file.toString().equals("matrix2.txt")) {
System.out.println("Input filename:" + "matrix2.txt");
}else{
System.out.println("Input filename:" + "matrix.txt");
file = new File("matrix.txt");
}
Scanner scnr = new Scanner(file);
int row = 0;
int col = 0;
while(scnr.hasNextLine()) {
String line = scnr.nextLine();
row++;
}
scnr = new Scanner(file);
String sn = scnr.nextLine();
it goes like that ...... But it keeps reading the else condition, not even read the other if conditions.