import java.util.Scanner; public class csv_demo { // private static final Exception ArrayIndexOutOfBoundsException = null;
public static void main(String[] args) throws ArrayIndexOutOfBoundsException, FileNotFoundException
{
//Get scanner instance
Scanner scanner = new Scanner(new File("C:/Users/Glocation/Desktop/abc.csv"));
//Set the delimiter used in file
scanner.useDelimiter(",");
int sum = 0, avg =0,max = 0,min = 0,a=0,b=0;
System.out.println("N1|N2|Sum|Avg|Max|Min");
try
{
while(scanner.hasNext())
{
String line=scanner.nextLine();
String[] arr=line.split(",");
for(int k=0;k<arr.length-1;k++)
{
a=Integer.parseInt(arr[k]);
b=Integer.parseInt(arr[k+1]);
sum = a+b;
avg= a+b/2;
if(a>b)
{
max=a;
min=b;
}
else
{
max=b;
min=a;
}
System.out.println(a+" |"+b+" |"+sum+" |"+avg+" |"+max+" |"+min);
}
}
}catch (Exception e)
{ }
}
}
I am getting error in the line of converting string array to get value in variable "a". My CSV file is 1 2 3 4 6 7 9 2 5 7 5 6 8