public class data {
public static void main(String[] args) {
String fileName = "Book1.csv";// File name is book1.csv
File file = new File(fileName); // read file
try{
Scanner inputStream = new Scanner(file);
while (inputStream.hasNext()){ // ignore first line
String data = inputStream.next();
System.out.println(data);
}
inputStream.close();
}catch (FileNotFoundException e) {
e.printStackTrace();
}}}
output
I want to calculate the sum of the values of followers. can you please help me
CodePudding user response:
You need to split String and transform to double. Like this:
double sum = 0;
while (inputStream.hasNext()){ // ignore first line
String data = inputStream.next();
double value = Double.valueOf(data.split(",")[1]); //[1] - number after ','
sum = value;
}
System.out.println(sum);