nfactorial
here is the java code on how to request the entry of a number and re factorial is easy, I hope you serve those interested in this program and this beginning, also for those who are studying programming.
first trip to bring the Scanner library, then a short int variable is created and initialized to 2 because that's factorial operation to pass, after a System.out.println asking you to enter the number, and the data is captured an int variable; for it is a sum equals sum i (i is for this) and closes on for a System.out.println factorial it is concatenated with the variable to which the data of the sample are captured number entered with the sum variable that is transforming the factorial number
Scanner s= new Scanner(System.in);
int sum=2;
System.out.print("Please enter number:");
int a= s.nextInt();
for(int i=a;i>2;i--){
sum=sum*i;
}
System.out.println("factorial"+a+" is "+sum);
follow me :D
first trip to bring the Scanner library, then a short int variable is created and initialized to 2 because that's factorial operation to pass, after a System.out.println asking you to enter the number, and the data is captured an int variable; for it is a sum equals sum i (i is for this) and closes on for a System.out.println factorial it is concatenated with the variable to which the data of the sample are captured number entered with the sum variable that is transforming the factorial number
Scanner s= new Scanner(System.in);
int sum=2;
System.out.print("Please enter number:");
int a= s.nextInt();
for(int i=a;i>2;i--){
sum=sum*i;
}
System.out.println("factorial"+a+" is "+sum);
follow me :D
Comentarios
Publicar un comentario