Linked Questions

Popular Questions

finding the Average from text file using ArrayList

Asked by At
name, place, money
-----------------
rohit1, us,1500
rohit2, us,1600
rohit3, ind,1700
rohit4, ind,1800

how we can compare value which is enter by the user "p" in arraylist o=val[1] and then sum all the common place money to find average and displaying the data
which is greater than money enter by the user

public static void main(String args[]) throws IOException 
    {
        int n;
        String place=null;
        int money=0, h=0;   
        BufferedReader br = new BufferedReader(new 
        InputStreamReader(System.in));
        //Scanner sc = new Scanner(System.in);
        System.out.println("Enter Number"); 
        n=Integer.parseInt(br.readLine());
        System.out.println("Enter a Origin"); 
        money = br.readLine();  
        System.out.println("You entered String "+n+o);
        List<String> arr = new ArrayList<String>();
        try (BufferedReader bf = new BufferedReader(new FileReader("C:\\Users\\RhlSin\\Desktop\\car_input1.txt")))
        {

            String sCurrentLine;
            while ((sCurrentLine = bf.readLine()) != null) 

            {
                 String[] val = sCurrentLine.split(",");
                 if (val[1]==place)
                 {
                    money= Integer.parseInt(val[2]) ;
                     h= h+money;
                    //arr.add(val[0]);
                    //arr.add(sCurrentLine);
                    //System.out.println(o);
                    System.out.println(h);

                 }



            }

        } catch (IOException e) {
            e.printStackTrace();
        }   
    }
}

Related Questions