Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5bf5fed

Browse files
Fibonacci Series
1 parent e771236 commit 5bf5fed

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.java.series;
2+
3+
/*
4+
* Fibonacci Series
5+
* ----------------
6+
* In mathematics, the Fibonacci numbers,
7+
* commonly denoted Fn, form a sequence,
8+
* called the Fibonacci sequence, such that
9+
* each number is the sum of the
10+
* two preceding ones, starting from 0 and 1.
11+
*
12+
* In other words, the previous two numbers
13+
* are added to get the next number, starting from 0 & 1.
14+
*
15+
* The Fibonacci Sequence is the series
16+
* of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
17+
*
18+
*/
19+
20+
public class FibonacciSeries {
21+
public static void main(String[] args) {
22+
int N = 10;
23+
int num1 = 0;
24+
int num2 = 1;
25+
26+
System.out.println("Fibonacci series N="+N);
27+
System.out.print(num1+" "+num2);
28+
int i = 2;
29+
while(i <= N){
30+
i++;
31+
int temp = num1+num2;
32+
num1 = num2;
33+
num2 = temp;
34+
System.out.print(" "+num2);
35+
}
36+
}
37+
}
38+
/*
39+
OUTPUT
40+
Fibonacci series N=15
41+
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610
42+
43+
Fibonacci series N=10
44+
0 1 1 2 3 5 8 13 21 34 55
45+
*/

‎InterviewPrograms/src/com/java/strings/Palindrome.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private static boolean checkPalindrome(String str){
3737
//then compare index 1 with index (n-2)
3838
//do this comparison for half of the string,
3939
//if is palindrome 2nd half the string is mirror(reverse) of the 1st half
40-
for(int i=0;i<str.length()/2;i++)
40+
for(int i=0;i < str.length()/2;i++)
4141
if(str.charAt(i) != str.charAt(strLen-i-1))
4242
return false;
4343
return true;

‎InterviewPrograms/src/com/java/strings/PermutationOfString.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static void main(String[] args) {
2828
public static void permutation(String p,String s){
2929
if(s.length() == 0)
3030
System.out.println(p);
31-
for(int i=0;i<s.length();i++){
31+
for(int i=0;i < s.length();i++){
3232
permutation(p+s.charAt(i), s.substring(0, i)+s.substring(i+1));
3333
}
3434
}

‎InterviewPrograms/src/com/java/strings/ReverseString.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static void main(String[] args) {
3636
public static String reverseString(String str){
3737
char[] charArray = str.toCharArray();
3838
int j = charArray.length-1;
39-
for(int i=0;i<charArray.length/2;i++,j--){
39+
for(int i=0 ;i < charArray.length/2;i++,j--){
4040
char temp = charArray[i];
4141
charArray[i] = charArray[j];
4242
charArray[j] = temp;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /