I'm trying to read data from a text file that looks something like

United States
155981460
50.28
Indonesia
40829720
16.8
India
38045000
3.24

I need to add all the numbers after each country together. I also need to which country has the highest number in the third line of each set of three.

Any tips would be great.
Thanks in advance.

What I'm basically trying to do is sum up the number in each second line of the set of three.

This is what I have:

public static void main( String[] args) throws Exception
   {
      File stats = new File("C:\\data.txt");
      Scanner fI = new Scanner(stats);

      int sum = 0;
      
      while(fI.hasNextInt()) {
          sum = fI.nextInt() + sum;
        }
        System.out.println( sum );
        fI.close();

If the data always comes in groups of three lines, read the three lines, process the data for the three lines and then read the next group of three lines.

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.