Suppose the file sample.txt content is:
1 casual 1 3 5 5
2 casual 5 2 5 3
3 casual 1 5 4 3
4 dress 4 5 4 4
5 athletic 2 4 5 2
Now, what i want is to take the last four numbers and possibly multiply each with four more numbers that will be taken from the user as:
Take the last four digits of the first line i.e. 1 3 5 5 then:
input1x1 + input2x3 + input3x5+ input4x5 = result.
Can anyone help me on how to achieve this, this is the code i have written till now which can read the file and then convert into list. :
import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] args) throws FileNotFoundException{
FileReader n = new FileReader("sample.txt");
Scanner in = new Scanner(n);
ArrayList<String> lines = new ArrayList<String>();
while (in.hasNext()) {
lines.add(in.nextLine());
}
in.close();
System.out.println(lines.get(1));
// for (int i = 0; i<lines.size()-1; i++) {
// System.out.println(lines.get(i));
// }
}
}