# Field Manual for Hackers

## java - write a program to print a factorial table using for loop

1. import java.util.Scanner;

class Test{

public static void main(String ar[])
{

Scanner sc=new Scanner(System.in);
long loop,factorial=1,outloop,inp;
System.out.println("Enter Number");
inp=sc.nextLong();

for(outloop=1;outloop<=inp;outloop++){

for (loop=1;loop <= outloop;loop++)
{
factorial=factorial*loop;
}
System.out.println("Factorial of "+outloop+" = "+factorial);
}

}
}

2. import java.util.Scanner;

class Test
{

public static void main(String ar[])
{

int i=1,j=1,limit,fac=1;
System.out.print("Enter the limit: ");
Scanner w=new Scanner(System.in);
limit=w.nextInt();
for(i=1;i<=limit;i++,fac=1)
{
for(j=i;j>=1;j--)
{
fac*=j;
}
System.out.println("The factorial of "+i+" is: "+fac);

}
}
}

3. import java.util.Scanner;
class FactorialTable
{
public static void main(String ar[])
{
int N,Number,Total=0,Fact,Number1=1,i,j;
Scanner scan=new Scanner(System.in);
System.out.println("Enter the Number you want to calculate its Factorial");
N=scan.nextInt();
for(i=1;i<=N;i++)
{Number=i;
Fact=1;
for(j=Number;j>1;j=j-2)
{
Fact=Fact*(j*(j-1));
//Number=Number-2;
}
System.out.println(i+"! "+Fact);
}
}
}

4. import java.util.Scanner;
class Box
{
public static void main(String Args[])
{
System.out.println(" enter the number");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{int j=i;
int num=1;
while(j>=1)
{
num*=j;
j--;
}
System.out.println( +i+"! "+num);
}
}}

5. package forloop;
import java.util.*;
public class Facttable
{
public static void main(String args[])
{
int i,n,fact=1;
System.out.println("enter number");
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
for(i=1;i<=n;i++)
{
fact=fact*i;
}
System.out.println(fact);
}
}

6. import java.util.Scanner;
class Facmulti{
public static void main(String ar[]){
Scanner obj=new Scanner(System.in);
int num,fact=1,i;
System.out.println("enter the value of number");
num=obj.nextInt();
for(i=1;i<=num;i++){
fact=fact*i;
System.out.println(i+"! "+fact);
}
}
}

7. package com.example.myapplication;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Factorial extends Activity {
int num,count,fact=1;
Button btfact;
EditText etfact;
TextView tvfact;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.factorial);

btfact=findViewById(R.id.btfact);
etfact=findViewById(R.id.etfact);
tvfact=findViewById(R.id.tvfact);

btfact.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
num=Integer.parseInt(etfact.getText().toString());
for (count=1;count<=num;count++) {

fact = fact * count;
}
tvfact.setText("Result="+fact);
}

});
}
}