JAVA CODE
//Sum2 program import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class Sum2 extends Applet implements ActionListener { Label Prompt; TextField NumText; int Num; public void init() { Prompt = new Label("Enter a number : "); add(Prompt); NumText = new TextField(3); add(NumText); NumText.addActionListener(this); } public void paint( Graphics g ) { double sum = 0; for (int i=1; i<=Num; i++) { sum = sum+1.0/i; } g.drawString(" The Sum is " + sum, 20, 20 ); int sqrsum = 0; for (int i=1; i<=Num; i++) { sqrsum = sqrsum + i*i; } g.drawString(" The Sqrsum is " + sqrsum, 50, 50 ); } public void actionPerformed( ActionEvent e ) { Num = Integer.parseInt(NumText.getText()); repaint(); } }