Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

dylan kane
2,772 PointsJava Code question
how would i solve "output the product of the squares of the number from x up to y" when x is 4 and y is 7. is can be answered with for loops or while loops
1 Answer

patrickolila
2,196 Pointsint squares;
//With a for loop:
for (int i = 4; i <= 7; i++) { squares = i * i; System.out.println(squares); }
//With a while loop:
int j = 4; while (j <= 7) { squares = j * j; System.out.println(squares); j++; }
dylan kane
2,772 Pointsdylan kane
2,772 PointsThanks, that was pretty much what i needed!