There's definitely a way to make a for loop out of variables. So if this button I made is clicked, the program will parse the ints in the textfields and send them to variables num1-num5
if (e.getSource() == calc)
{
num1 = Integer.parseInt(num1field.getText());
num2 = Integer.parseInt(num2field.getText());
num3 = Integer.parseInt(num3field.getText());
num4 = Integer.parseInt(num4field.getText());
num5 = Integer.parseInt(num5field.getText());
sum = num1 + num2 + num3 + num4 + num5;
avg = sum / 5;
ans = "";
ans = Integer.toString(avg);
answerfield.setText(ans);
}
I'm trying to turn the sum statement into a for loop that produces the same result. How do I go about doing this?