-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask26.java
More file actions
42 lines (42 loc) · 840 Bytes
/
task26.java
File metadata and controls
42 lines (42 loc) · 840 Bytes
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
//Prime numbers using recursion
import java.util.Scanner;
public class task26
{
public static void main(String[] args)
{
int n, x;
Scanner s = new Scanner(System.in);
System.out.print("Enter any number:");
n = s.nextInt();
if(n>1)
{
task26 obj = new task26();
x = obj.prime(n, 2);
if(x == 1)
{
System.out.println(n+" is prime number");
}
else
{
System.out.println(n+" is not prime number");
}
}
else
System.out.println(n+" is not prime number");
}
int prime(int a,int b)
{
if(b < a)
{
if(a % b != 0)
{
return(prime(a, ++b));
}
else
{
return 0;
}
}
return 1;
}
}