Here i have this code which read from a text file and fills the 2d array.Then calculates the sum of each column.I want all those column names whose sum is greater than 5 to be written in output file.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication30;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
/**
 *
 * @author anku saxsena
 */
public class JavaApplication30 {

    /**
     * @param args the command line arguments
     */





    public static void main(String[] args) {

        BufferedReader br = null;
                String[] line=new String[55];
                int i=0;
                int[] sum=new int[12];
                int[][] m=new int[55][12];
        int row=0,col=0;
        int no_of_row=55,no_of_col=12;
        try {

            String sCurrentLine;

            br = new BufferedReader(new FileReader("F:\\New Folder\\transa.txt");

                        while ((sCurrentLine = br.readLine()) != null)
             {
                System.out.println(sCurrentLine);
                line[i]=sCurrentLine;
                               i++;
                         }
                         col=0;        
                         for(i=0;i<55;i++)
                         {
                             for(int j=0;j<12;j++)
                            {
                                String s=""+line[i].charAt(j);
                                m[i][j]=Integer.parseInt(s);
                               // System.out.println(m[i][j]);
                            }
                         }
                         //sum of columns
                         for(int j=0;j<12;j++)
                         {
                             sum[j]=0;
                             for(i=0;i<55;i++)
                             {
                                 String s=""+m[i][j];
                                 //System.out.print(s);
                                sum[j]=sum[j]+Integer.parseInt(s);
                             }
                         }
                         for(i=0;i<12;i++)
                         {System.out.print(" "+sum[i]);
                              if(sum[i]>min_sup)
                              { System.out.println();

                              }
                              }                            

        } 
        catch (IOException e)
         {
            System.out.println("Error :"+e);
        } 
        finally 
        {

        try {
                if (br != null)br.close();

        }
         catch (IOException ex)
         {
                System.out.println("Error :"+ex);
        }
        }

    }
}

``

keep an array of booleans, with the same indexes.
if sum > 5 -> set to true.
later on:
if indexes[i] -> show columnNames[i]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.