Q:

Why does the output differ when input "i" instead of "j" as the key in HashMap?

I am using 2 for loops as below to get the sum of the numbers in an int[]. getTotal() is suppose to give the sum of the values in array which are below 100. The sum is calculated by adding the values one by one until it exceeds hundred. When it exceeds hundred it starts again with the next value and adds one by one like before.
private static HashMap<Integer,Integer> getTotal(){
    int total = 0;
    HashMap<Integer,Integer> finalTotal = new HashMap<Integer, Integer>();
    for (int i = 0; i < array.length; i++) {
        total += array.get(i);
        for (int j = i+1; j < array.length; j++) {
            if(total>100){
                finalTotal.put(j,total - array.get(j));
                total = 0;
            }
            else if(total<100){
                total += array.get(j);
            }
        }
    }
    return finalTotal;
}

When printing the result in the hash-map it gives 2 different maps of answers when I use i and j for as the key. Isn't it suppose to give the same values and just different keys as answers? Not only the value the amount length of the hashmap also changes.
It would be great if you could point out any mistakes and explain why this happens.

A:

Modifying your code, for smaller numbers for examples sake
//*******************************************************************
// Welcome to CompileJava!
// If you experience any issues, please contact us ('More Info')  -->
//*******************************************************************

import java.lang.Math; // headers MUST be above the first class
import java.util.HashMap;

// one class needs to have a main() method
public class HelloWorld
{
  public static int[] array = {1,2,3,4,5,6,7,8,9,10};
  // arguments are passed using the text field below this editor
  public static void main(String[] args)
  {

    System.out.println(getTotal());
  }

  private static HashMap<Integer,Integer> getTotal(){
    int total = 0;
    HashMap<Integer,Integer> finalTotal = new HashMap<Integer, Integer>();
    for (int i = 0; i < array.length; i++) {
        total += array[i];
        System.out.println("");
        System.out.println("//i = " + i + "; arr[i] = " + array[i]);
        System.out.println("total += " + array[i] + "; // total = " + total);
        for (int j = i+1; j < array.length; j++) {
            System.out.println("    //j = " + j + "; arr[j] = " + array[j]);
            if(total>5){
                finalTotal.put(j,total - array[j]);
                System.out.println("    finalTotal += (" + j+", "+total + "-" + array[j]+")");
                total = 0;
            }
            else if(total<5){
                total += array[j];
                System.out.println("    total += " + array[j]+"; //total = "+total);
            }
        }
    }
    return finalTotal;
  }
}

Stepping through your code, and recording the results gives 
//i = 0; arr[i] = 1
total += 1; // total = 1
    //j = 1; arr[j] = 2
    total += 2; //total = 3
    //j = 2; arr[j] = 3
    total += 3; //total = 6
    //j = 3; arr[j] = 4
    finalTotal += (3, 6-4)
    //j = 4; arr[j] = 5
    total += 5; //total = 5
    //j = 5; arr[j] = 6
    //j = 6; arr[j] = 7
    //j = 7; arr[j] = 8
    //j = 8; arr[j] = 9
    //j = 9; arr[j] = 10

//i = 1; arr[i] = 2
total += 2; // total = 7
    //j = 2; arr[j] = 3
    finalTotal += (2, 7-3)
    //j = 3; arr[j] = 4
    total += 4; //total = 4
    //j = 4; arr[j] = 5
    total += 5; //total = 9
    //j = 5; arr[j] = 6
    finalTotal += (5, 9-6)
    //j = 6; arr[j] = 7
    total += 7; //total = 7
    //j = 7; arr[j] = 8
    finalTotal += (7, 7-8)
    //j = 8; arr[j] = 9
    total += 9; //total = 9
    //j = 9; arr[j] = 10
    finalTotal += (9, 9-10)

//i = 2; arr[i] = 3
total += 3; // total = 3
    //j = 3; arr[j] = 4
    total += 4; //total = 7
    //j = 4; arr[j] = 5
    finalTotal += (4, 7-5)
    //j = 5; arr[j] = 6
    total += 6; //total = 6
    //j = 6; arr[j] = 7
    finalTotal += (6, 6-7)
    //j = 7; arr[j] = 8
    total += 8; //total = 8
    //j = 8; arr[j] = 9
    finalTotal += (8, 8-9)
    //j = 9; arr[j] = 10
    total += 10; //total = 10

//i = 3; arr[i] = 4
total += 4; // total = 14
    //j = 4; arr[j] = 5
    finalTotal += (4, 14-5)
    //j = 5; arr[j] = 6
    total += 6; //total = 6
    //j = 6; arr[j] = 7
    finalTotal += (6, 6-7)
    //j = 7; arr[j] = 8
    total += 8; //total = 8
    //j = 8; arr[j] = 9
    finalTotal += (8, 8-9)
    //j = 9; arr[j] = 10
    total += 10; //total = 10

//i = 4; arr[i] = 5
total += 5; // total = 15
    //j = 5; arr[j] = 6
    finalTotal += (5, 15-6)
    //j = 6; arr[j] = 7
    total += 7; //total = 7
    //j = 7; arr[j] = 8
    finalTotal += (7, 7-8)
    //j = 8; arr[j] = 9
    total += 9; //total = 9
    //j = 9; arr[j] = 10
    finalTotal += (9, 9-10)

//i = 5; arr[i] = 6
total += 6; // total = 6
    //j = 6; arr[j] = 7
    finalTotal += (6, 6-7)
    //j = 7; arr[j] = 8
    total += 8; //total = 8
    //j = 8; arr[j] = 9
    finalTotal += (8, 8-9)
    //j = 9; arr[j] = 10
    total += 10; //total = 10

//i = 6; arr[i] = 7
total += 7; // total = 17
    //j = 7; arr[j] = 8
    finalTotal += (7, 17-8)
    //j = 8; arr[j] = 9
    total += 9; //total = 9
    //j = 9; arr[j] = 10
    finalTotal += (9, 9-10)

//i = 7; arr[i] = 8
total += 8; // total = 8
    //j = 8; arr[j] = 9
    finalTotal += (8, 8-9)
    //j = 9; arr[j] = 10
    total += 10; //total = 10

//i = 8; arr[i] = 9
total += 9; // total = 19
    //j = 9; arr[j] = 10
    finalTotal += (9, 19-10)

//i = 9; arr[i] = 10
total += 10; // total = 10
{2=4, 3=2, 4=9, 5=9, 6=-1, 7=9, 8=-1, 9=9}

This is only a few steps in, and it really doesn't seem like it does anything like you asked. I recommend looking up how to use a debugger, and step through your code.
Notice that j is not the same thing as arr[j]
Notice that loops within loops, still loop, and take care of the start positions of the loop.
Hashmaps will update their value, should you insert a duplicate, given your code (note that you don't handle the case where total==5/100, loop enough times and it's bound to happen) and you will get differing values.
Start on smaller problems / inputs that you are able to debug , and work your way up.

