Sunday 8 November 2020

 

 Write a program to accept a number through command line argument and find factorial of the number.



Program:-


class Fact

{

    public static void main(String args[])

     {

        if(args.length !=1)

         System.out.println("Wrong arguments");

        else

         {

            int n = Integer.parselnt(args[0]);

            int f=1;

            for(int i = 1;i<=n;i++)

                 f = f*i;

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



          }


      }


 }

 

 

 

OUTPUT:-

 

C:\java\bin>java Fact 5

Factorial of 5 is 120

 


No comments:

Post a Comment

Student Marks Calculation app using java

      import javax.swing. *; import java.awt.event.ActionEvent ; import java.awt.event.ActionListener ; public class Student { private J...