forked from twowaits/make-pull-request
-
Notifications
You must be signed in to change notification settings - Fork 0
/
6thOct-0.java
55 lines (51 loc) · 1.03 KB
/
6thOct-0.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
import java.util.*;
class Hacktober
{
static void printFibonacciNumbers(int n)
{
int f1 = 0, f2 = 1, i;
if (n < 1)
return;
for (i = 1; i <= n; i++)
{
int n;
if(isPrime(f2)==true)
{
n=f2;
f2=0;
}
if(f2%5==0)
{
n=f2;
f2=0;
}
System.out.print(f2+" ");
f2=n;
int next = f1 + f2;
f1 = f2;
f2 = next;
}
}
static boolean isPrime(int h)
{
int c=0;
for(int i=1;i<=h,i++)
{
if(h%i==0)
{
c++;
}
}
if(c==2)
return true;
else
return false;
}
// Driver Code
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
printFibonacciNumbers(n);
}
}