JAVA CODE
// The Output program import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class Output extends Applet implements ActionListener { Label Prompt; TextField NumText; int Num; public void init() { Prompt = new Label(" Enter a number "); add(Prompt); NumText = new TextField(10); add(NumText); NumText.addActionListener(this); } public void paint( Graphics g ) { int sum = 0, column = 10; for (int i = 1; i <= Num; i++) { sum = sum + i; if(i == Num) g.drawString(i + " = ", column, 50 ); else g.drawString(i + " + ", column, 50 ); if(i < 10) column = column + 20; else column = column + 30; } g.drawString (Integer.toString(sum), column, 50); } public void actionPerformed( ActionEvent e ) { Num = Integer.valueOf(NumText.getText()).intValue(); repaint(); } }