Q:

Addition of every six consecutive numbers to give their sums

I want my program to add every six consecutive weights and display their sum and then calculate the sum of the next six weights and so on, and finally display the total as the addition of all the sums.
Additionally if the value of the entered weight is more than 65 i want the counter to increase by one and consider as two weights rather than one (might be a bit confusing, i have added the code and solution)
package trial;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class trail1 
{
public void display() throws IOException
{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("enter number of weights");
    int n= Integer.parseInt(br.readLine());
    int Number[] = new int[n];
    int i, sum=0,total=0;
    String m;
    System.out.println("enter the numbers");
    for(i=0;i<n;i++)
    {
        m=br.readLine();
        Number[i]=Integer.parseInt(m);

        if(Number[i]>65)
        {
            sum = sum + Number[i];
            if((i!=0)&&((i%10)==0))
            {
                System.out.println("the sum is out " + sum);
                total=total +sum;
                sum =0;
            }
            else  if(i==(n-2))
            {
                System.out.println("the sum is bad " + sum);
                total = total+sum;
            }
            i++;// this increases the counter by one
        }
        else if(Number[i]<65)
        {
            sum = sum+ Number[i];
            if(((i+1)%6)==0)
            {
                System.out.println("the sum is " + sum);
                total=total +sum;
                sum =0;
            }
            else  if(i==(n-1))
            {
                System.out.println("the sum is bad " + sum);
                total = total+sum;
            }

        }

    }
    System.out.println("the total of the sums is " + total);
}

public static void main(String[] args) throws IOException
{
    trail1 one = new trail1();
    one.display();
}

}

this works just fine but the problem is when the number of weights go above 20 and i no longer get the sum after six times but after five times.
the run after the user enters number of weights as 24 i get the answer as this
enter number of number
24
enter the numbers
100
100
100
100
100
100
the sum is out 600
100
100
100
100
100
the sum is out 500
100
the sum is bad 100
the total of the sums is 1200

where as what i want is
enter number of number
24
enter the numbers
100
100
100
100
100
100
the sum is out 600
100
100
100
100
100
100
the sum is bad 100
the total of the sums is 1200

A:

Solved It! Take a third variable 'j', and use it as - 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Ans {
    public void display() throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("enter number of weights");
        int n = Integer.parseInt(br.readLine()); // store the number of weights
        int Number[] = new int[n];
        int i, sum = 0, total = 0, j = 0;
        String m;
        System.out.println("enter the numbers");
        for (i = 0; i < n; i++) {
            m = br.readLine();
            Number[i] = Integer.parseInt(m); // store the inputed number in the array 

            if (Number[i] > 65) { // if the number > 65
                sum += Number[i];
                if ((i != 0) && ((j % 5) == 0) && (j != 0) && (i != (n - 2))) {
                    System.out.println("the sum is out " + sum);
                    total = total + sum;
                    sum = 0;
                    j = -1;
                } else if (i == (n - 2)) {
                    System.out.println("the sum is bad " + (sum * 1 / 6));
                    total += sum;
                }
                i++;
                ++j;
            } else if (Number[i] < 65) {
                sum = sum + Number[i];
                if (((i + 1) % 6) == 0) {
                    System.out.println("the sum is " + sum);
                    total = total + sum;
                    sum = 0;
                } else if (i == (n - 1)) {
                    System.out.println("the sum is bad " + sum);
                    total = total + sum;
                }

            }

        }
        System.out.println("the total of the sums is " + total);
    }

    public static void main(String[] args) throws IOException {
        Ans one = new Ans();
        one.display();
    }

}

The output is correct. In the above code, I used (sum * 1 / 6) as you see, I had not reset the value of sum to 5 and then added 100, but the output would nevertheless be the same, because 100 = 1 / 6 th of 600, and this would be your required output for all possible inputs. Here is the output - 
enter number of weights
24
enter the numbers
100
100
100
100
100
100
the sum is out 600

100
100
100
100
100
100
the sum is bad 100
the total of the sums is 1200

