-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrimeFact.java
44 lines (40 loc) · 951 Bytes
/
PrimeFact.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//prime mnumber
//a number that is divisible only by itself and 1
import java.util.Scanner;
public class PrimeFact{
public static void main(String a[]){
Scanner scanner = new Scanner(System.in);
System.out.println("Enter n number ");
int n =scanner.nextInt();
factorial(n);
// primeNumber(n)
}
public static void primeNumber(int n){
System.out.println("** Prime number ** ");
boolean f=false;
for(int i = 2; i<=n/2; i++)
{
//6==/2
if(n%i ==0)
{
f=true;
break;
}
}
if(!f){
//false
System.out.println("is Prime number ");
}else{
//true
System.out.println("not prime number ");
}
}//factorial == !5 5*4 5*3 5*2 5*1 = 120
public static void factorial(int n){
System.out.println("** Factorial ** ");
int fact=1;
for(int i=1; i<=n; i++){
fact=fact*i;
}
System.out.println("Factorial of given number is "+fact);
}
}