Hello i need to add two integers in the same row of a file, separated by tab
my file abc.txt has the following entry
12 123
15 456
my program needs to add 12 with 123 and 15 with 456
i am being able to split the two entries in a row and convert them to integer but i dont know how to treat them as separate numbers and add them
for example if i try to add then 12 adds with 12 and 123 adds with 123. wheres it should be 12+123
here is my program
import java.io.*;
public class test {
public static void main(String[] args) {
String s = "";
FileInputStream finp = null;
InputStreamReader inpr = null;
BufferedReader br = null;
try {
finp = new FileInputStream(args[0]);
inpr = new InputStreamReader(finp);
br = new BufferedReader(inpr);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try{
while(true){
s = br.readLine();
if(s==null)
break;
for(int i =0;i<2;i++){
String [] addrs = s.split("\t");
int a = Integer.parseInt(addrs[i]);
System.out.println(a+a);}
}
}catch(IOException e){
e.printStackTrace();
}
}
}