Note that there are some explanatory texts on larger screens.

plurals
  1. POError in Calculating sum of particular column
    text
    copied!<p>i am here with another problem in my code since i am new to java. my task is to read a text file that contains some 300 records and record has 13 fields . i am trying to calculate the sum of each field for example, if age is my first field them sum of the age of all 300 people and then store it in an array index. </p> <pre><code>import java.io.*; import java.util.Vector; public class Mean { private static Vector contents; private static BufferedReader br; private static FileInputStream inputstream; private static FileOutputStream outputstream; public Mean() { contents = new Vector(); } public void doDuplicationRemoval(String filename) { try{ inputstream = new FileInputStream(filename); br = new BufferedReader(new InputStreamReader(inputstream)); String string = ""; while((string = br.readLine())!= null) { String[] split = string.split(","); Vector vector = new Vector(); for(int i=0; i&lt;split.length; i++) vector.add(split[i].trim()); if(!vector.contains("?")) { contents.add(split); } } } catch(Exception err){ System.out.println(err); } } public void doDataConv(String filename) { DataConversion.readFile(contents); DataConversion.writeFile(filename); } public static void doDataConversion(Vector contents) { DataConversion.readFile(contents); for(int i=0; i&lt;contents.size(); i++) { String string = ""; String[] split = (String[])contents.get(i); split[0] += getAge(split[0]); System.out.println(split[0]); } } private static String getAge(String src) { String age = src; return age; } public static void main(String [] args) { Mean dr; dr = new Mean(); dr.doDuplicationRemoval("input.txt"); dr.doDataConv("inp_out.txt"); dr.doDataConversion(contents); } } </code></pre> <p>the input is<br> 63<br> 67<br> 50 </p> <p>my aim is to get output as 180</p> <p>but am getting<br> 6363<br> 6767<br> 5050 </p> <p>can someone help me to fix the problem.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload