-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDay25_prob1.java
61 lines (54 loc) · 1.29 KB
/
Day25_prob1.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
Richa and her daughter Ahaana are playing a game. Richa is going to tell one number and Ahaana need to tell the prime factors of the number. Help Ahaana by completing the code to find prime factor of the number. Write a method which calculate prime factors and print and call the method in main.
Input Format
An integer value
Constraints
N will be lie between 10-50
Output Format
All the prime factors will be printed exectly once with space.
*/
// kirtan jain
import java.io.*;
import java.util.*;
public class Solution
{
static boolean isPrime(int n)
{
for(int i=2;i<n;i++)
{
if(n%i==0)
{
return false;
}
}
return true;
}
static void printPrime(int nn)
{
int temp;
for(int i=2;i<=nn;i++)
{
temp = nn%i;
if(temp==0)
{
if(isPrime(i))
{
System.out.print(i+" ");
}
}
}
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if(n>10 && n<50)
{
printPrime(n);
}
else
{
System.out.println("Invalid Input");
}
}
}