I'm trying to write an applet that will display numbers 0-5, then their square, and cube. I've got the number and the square of that number working (not very effeicent, but working). The cubed numbers are coming from the squared numbers and not the original. Can anyone help me fix this code and maybe clean it up some? Thanks for any replies.
Code:package sumsquare; import java.awt.Graphics; import javax.swing.*; public class SumSquare extends JApplet { int a = 0; int b = 1; int c = 2; int d = 3; int e = 4; int f = 5; int x = 25; int y = 40; public void paint(Graphics g) { super.paint(g); g.drawString("Number", 25, 25); g.drawString("Sqaure", 75, 25); g.drawString("Cube", 125, 25); while (x < 126) { g.drawString("" + a, x, 40); g.drawString("" + b, x, 55); g.drawString("" + c, x, 70); g.drawString("" + d, x, 85); g.drawString("" + e, x, 100); g.drawString("" + f, x, 115); x = x + 50; a = a * a; b = b * b; c = c * c; d = d * d; e = e * e; f = f * f; } } }


Reply With Quote