FACTORIAL


/*
<applet code=factorial width=300 height=300>
</applet>
*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;


public class factorial extends Applet implements ActionListener
{
TextField tf,res;
Button chk;
public void init()
{
chk=new Button("  CLICK  ");
tf=new TextField(20);
res=new TextField(20);
add(tf);
add(res);
add(chk);
chk.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
int fact=1;
if(ae.getSource()==chk)
{
int no=Integer.parseInt(tf.getText());
for(int i=1;i<=no;i++)
{
fact=fact*i;
}
res.setText(Integer.toString(fact));
}
}//action per
}//class

OUTPUT:







Comments

Popular posts from this blog

Write a java program to create an abstract class named Shape that contains two integers and an abstract method named printArea(). Provide three classes named Rectangle, Triangle and Circle such that each one of the classes extends the class Shape. Each one of the classes contain only the method printArea( ) that prints the area of the given shape.

Create Employee Class with Method getdata and setdata. Create following subclasses to generate biodata. i) Personal record ii)) Professional record iii) Academic record Assume appropriate data members and member function to accept required data & print bio-data. Use Overriding at suitable places.Create bio-data using multilevel inheritances.

Exception_Handling Program