SY-9-a Java AWT program to print the factorial for an input value in easy way

Java AWT program to print the factorial for an input value

A Java program to print the factorial for an input value with AWT.

Design a AWT program to print the factorial for an input value

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.awt.*;
import java.awt.event.*;

class Factorial extends Frame implements ActionListener
{
	TextField tf;
	Button b;
	Label n, l, r;
	Factorial()
	{  
		n = new Label("AWT Factorial Program");
		l = new Label("Enter number");
		r = new Label();

		tf = new TextField();

		b = new Button("Factorial");  
//itvoyagers.in
		n.setBounds(30, 40, 200, 20);
		l.setBounds(30, 70, 150, 20);
		r.setBounds(30, 170, 200, 20);

		tf.setBounds(30, 90, 190, 30);

		b.setBounds(30, 130, 190, 30);  

		add(n);
		add(l);
		add(r);
		add(tf);
		add(b);

		setSize(250,210);
		setLayout(null);//no layout manager  
		setVisible(true);//now frame will be visible, by default not visible  

		b.addActionListener(this);

		addWindowListener(new WindowAdapter()
		{  
            public void windowClosing(WindowEvent e)
            {  
                dispose();  
            }  
        });
	}
//itvoyagers.in
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==b)
		{
			int num = Integer.parseInt(tf.getText());
			r.setText("Factorial of "+num+" is "+getFactorial(num));
		}
	}

	public int getFactorial(int x)
	{
		int rsl = 1;
		for(int i = x; i > 0; --i)
		{
			rsl *= i;
		}
		return(rsl);
	}
//itvoyagers.in
	public static void main(String[] args)
	{
		Factorial factorial = new Factorial();
	}
}

Output

awt factorial program itvoyagers

PRACTICALS/PRACTICE PROGRAM IN Java

SYIT Practical Programs
SY-1-a Easy Java program to print multiplication table
SY-1-b Easy program to print inverted pyramid pattern of stars in Java
SY-1-c Easy Java program to print the area and perimeter of a circle
SY-2-c Easy Java program to reverse a string
SY-3-a Easy Java program to count the letters, spaces, numbers and other characters
SY-3-c Easy to find the smallest and largest element from the array in Java
SY-4-a Easy java program to sort array in ascending and descending order
SY-4-b Easy program on constructor and destructor in Java
SY-4-c Implementation of abstract class in Java in easy way
SY-5-a Easy java program to implement single level inheritance
SY-5-b Easy java program to implement method overriding
SY-5-c Easy java program to implement multiple inheritance
SY-6-a Easy program to create package in Java
SY-6-b easy java program to add two matrices and print the resultant matrix
SY-6-c Java program for multiplying two matrices in easy way
SY-7-a easy java program to implement the vectors
SY-7-c Easy and simple java program to implement multithreading
SY-8-a java program to open a file and display the contents in the console window in easy way
SY-8-b Java program to copy the contents from one file to other file in easy way
SY-9-a Java AWT program to print the factorial for an input value in easy way
SY-9-b Java AWT program to perform various string operations in easy way
SY-9-c Easy java program to implement exception handling
SY-10-a Java AWT program to accept and display student details in easy way
ST-10-b Java program to design a calculator based on AWT application in easy way
SYCS Practical Programs Semester 3
Java program to solve quadratic equations to print the roots of ax2+bx+c=0
Java program to add two matrices
Accept n strings. Sort names in ascending order
Create a package: Animals. In package animals create interface Animal with suitable behaviors. Implement the interface Animal in the same package animals
Demonstrate Java inheritance using extends keyword.
Demonstrate method overloading and method overriding in Java.
Demonstrate creating your own exception in Java.
Using various swing components design Java application to accept a student’s resume. (Design form)
Write a Java List example and demonstrate methods of Java List interface.
Design simple calculator GUI application using AWT components
Write a Java program that takes a number as input and prints its multiplication table upto 10.
Java program to print reverse pyramid
Write a Java program to print the area and perimeter of a circle
SYCS Practical Programs Semester 4
SYCS-5 Java application to demonstrate servlet life cycle in easy way
Practice Program
1 – Best Java program to find factorial of a number
2 – Java program to check if number is Even or Odd
3 – Best Java program to check prime number
4 – Simple and easy Java program to calculate area
5 – Best Java program to convert decimal to binary
6 – Best Java program to implement stack using array
7 – Best Java program to check palindrome number
8 – Best Java program to reverse a number
9 – Easy and simple billing system program in java swing
10 – Easy and simple java program for billing system of tour and travels
More coming soon…

CHECKOUT OTHER RELATED TOPICS

We are aiming to explain all concepts of Java in easiest terms as possible.
ITVoyagers-logo
ITVoyagers
Author

Leave a Comment