How can I store user input in arrays and then print them out? : <p>I am a beginner programmer and I am making a little application for practice.</p>

<p>You enter your budget, then you add an expense(name, amount)
and it subtracts and tells you your current budget.</p>

<p>I want to make it so you can see all of your expenses after each execution.</p>

<p>I have tried to make for loops that store the names of the expenses and then print them.
But I am doing something wrong :/.</p>

<p>Sorry for my bad English, I am from Croatia!</p>

<p>Here is some beginner ugly code.</p>

<pre><code> int length = 0;
 String[] listOfNames = new String[length]; 

 boolean active = true;
 int budget = 0; 
 Scanner input = new Scanner(System.in); //user input

 System.out.println("Enter current budget in HRK");
 int enteredAmount = input.nextInt(); //user input for budget

 budget = enteredAmount;



 while(active)
 {
     System.out.println("Current budget is " + budget +  " HRK");
     System.out.println("Enter expense name and amount");

     System.out.println("Name: ");
     String name = input.next(); //name of expense


     for(int i=0; i&lt;listOfNames.length;i++){ //adds entered expense names to array

     listOfNames[i] = name;
     length++;              
     }


     System.out.println("Amount: ");

     int enteredAmount1 = input.nextInt();

     budget -= enteredAmount1; // subtracts the budget from the users input

     System.out.println("Expense: " + name + ", Amount: " + enteredAmount1); // prints final result

     for(int j=0; j&lt;listOfNames.length; j++) // prints stored strings in array
     {
       System.out.println(listOfNames[j]);
     }


 }
</code></pre>

<p>}
}</p>
