data file looks like below
12,234,123
123,452,622
(here is a empty line)
1,000,010
20,000
result supposes to looks like below
12234123
123452622
sum: 125686745
product:1510334562...
1000010
20000
sum: 1020010
product: 20000200000
can not use any utility library such as java.math.BigDecimal javautil.LinkedList etc.
- I dont know how to display each number on one row
my result is like
12
234
123
but I need to display it on one row as
12234123
- the problem of the space, there is a empty line between each pair of numbers I only can get first pair of numbers since my while statement works only when line is not null.
Shown on below:
while((Line = File.readLine())!= null)
I dont know how to modify it.
for the method of sum and the method of product. hope someone can give me some clues.
here is the code. (blank line problem solved)
public static void main (String[] args){
if (args.length == 0)
System.out.println("No file specified.");
else{
FileReader theFile;
BufferedReader inFile;
String num1,num2;
try{
theFile = new FileReader(args[0]);
inFile = new BufferedReader(theFile);
while((num1 = inFile.readLine())!= null){
if(num1.length()==0){
}
else{
num2 = inFile.readLine();
num1.replace(",", "");
num2.replace(",", "");
System.out.println(num1);
System.out.println(num2);
}
}
}
catch (Exception e) {
System.out.println(e);
}
}
}