THINK FIRST·CODE LATER

← All labs

A table of squares and cubes

Problem

Write SquaresTable, which prints a small table. The columns are separated by a tab (\t), and every square and cube is computed by Java (3 * 3, 3 * 3 * 3) — do not type the results. The program takes no input and prints exactly:

n	square	cube
1	1	1
2	4	8
3	9	27
4	16	64
5	25	125
Sum of the squares: 55

In the last line the parentheses around the sum are necessary. What would be printed without them?

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.