Rotate your phone or change to desktop for better experience

Rotate your phone or change to desktop for better experience

Pgm 2 || Program to list the factorial of the numbers 1 to 10. To calculate the factorial value, use while loop. (Hint: Fact of 4 = 4*3*2*1)

 import java.util.*;

public class Pgm2 {

public static void main(String[] args) {

long fact = 1;

int i=1;

Scanner in = new Scanner(System.in);

System.out.println("Enter Number between 1 to 10 ");

int n = in.nextInt();

while(i <= n)

{

fact = fact * i;

i++;

}

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

}

}


Post a Comment

0 Comments