Hey,
I'm pretty new to Java and I was hoping someone could help me out. I wanted to know how to store the information that a loop shows. I've been asked to create a project which adds up the squares of the numbers from a to c, and this is my code so far.
Class 1:
public class sumSquares {
public sumSquares(int a, int c)
{ while (a<=c)
{ u=(a*a);
a=a+1;
System.out.println(u);
}
}
private int u;
}
Class 2:
public class sumSquaresTester {
public static void main(String[] args){
sumSquares sum=new sumSquares(1,5);
System.out.println(sum);
}
}
I am able to get the squares that i need from the variable u, but how do i store the values i get after each cycle of the loop? Thanks in advance for the help.