0% found this document useful (0 votes)
10 views2 pages

Solution: Code

Uploaded by

Avi Manyu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Solution: Code

Uploaded by

Avi Manyu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

NAME: RANJIT RAJ UID: 20BCS9943

SECTION: 44-B SUB: JAVA

Question 1
Write a Java program to find the factorial of a number

Solution:
Code:
import java.util.Scanner;

public class Main {

public static void main(String[] args) {

int number;

System.out.println("Enter the number: ");

Scanner scanner = new Scanner(System.in);

number = scanner.nextInt();

scanner.close();

long fact = 1;

int i = 1;

while(i<=number)

{
fact = fact * i;

i++;

System.out.println("Factorial
em.out.println("Factorial of "+number+" is: "+fact);

Output:

You might also like