Question: I am stuck here:

System.out.println("Enter the number to be added to these factorial numbers:");
 System.out.println("1!/1 + 2!/2 + 3!/3 + "); //factorial ie. 5!/5 = 4 \* 3 \* 2 \* 1 
 n = scan.nextInt();

```
     while (!exit)
    {

        if (n <= 2) 
        {
            sum = 1;
            exit = true;
        }
        sum = sum + i - 1;

        i = i - 1;
        if (i == 2)
        {
            exit = true;
        }
    }

     //m2 = 1 * 1 + (2 * 2) + (2 * 1) + (3 * 3) + (3 * 2) + (3 * 1) + (n * n -1);  
     //System.out.println(m2);

```

Answer: 
For a single value such as balance or username you should definitely use [SharedPrefereneces](http://developer.android.com/intl/ru/reference/android/content/SharedPreferences.html) and [OnSharedPreferenceChangeListener](http://developer.android.com/intl/ru/reference/android/content/SharedPreferences.OnSharedPreferenceChangeListener.html).

For structured data such as balance operations you should definitely use a database:

* **SQLite**
* **Realm** (noSQL)
* **StorIO** (SQLite wrapper)

or some **ORM**.
You should store data in SharedPreferences rather than global variables because when app crashes, the data updated in static global variables at different times is lost and the default data in it remains.