-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6dd0d2f
commit 418a58c
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
Introduction to Java/Lecture 8/Functions and Scope/Exercises/FibonacciNumber.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//write a program to check whether a input n is part of Fibonacci Series | ||
//if yes print true else false. | ||
|
||
|
||
// --------------------------------------------------------------------------------------------------------- | ||
|
||
|
||
import java.util.Scanner; | ||
public class FibonacciNumber { | ||
|
||
public class Solution { | ||
public static boolean checkMember(int n){ | ||
int a = 0; | ||
int b = 1; | ||
int c; | ||
while(a<n){ | ||
c=a+b; | ||
a=b; | ||
b=c; | ||
} | ||
if(a==n){ | ||
return true; | ||
}else{ | ||
return false; | ||
} | ||
} | ||
} | ||
//pregiven code | ||
public static void main(String[] args) { | ||
Scanner s = new Scanner(System.in); | ||
int n = s.nextInt(); | ||
System.out.println(Solution.checkMember(n)); | ||
s.close(); | ||
} | ||
|
||
} |