AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



corejava-programming: Fabonacci Series

David is a student of Computer Science and he need your Java skill to solve the problem of space separeted Fibonacci Numbers upto "N" term. If the N is not greater than 0 then print "Invalid input". Sample Intput: 10 Sample Output: 0 1 1 2 3 5 8 13 21 34 NOTE:- For accepting input use Scanner class

corejava x 353
programming x 168
Posted On : 2016-11-04 21:59:05.0
profile Aarti Kumar - anyforum.in Aarti Kumar
5900
up-rate
4
down-rate

Answers


import java.util.Scanner;
class MyFib
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int N=s.nextInt();
if(N>0)
{
int[] f = new int[N];
f[0] = 0;
f[1] = 1;
for(int i=2; i < N; i++){
f[i] = f[i-1] + f[i-2];
}

for(int i=0; i< N; i++){
System.out.print(f[i] + " ");
}
System.out.println();
}
else
{
System.out.println("Invalid Input!!");
}
}
}

Posted On : 2016-11-10 20:21:32
Satisfied : 1 Yes  0 No
profile Sudheer Kumar Javvadi - anyforum.in Sudheer Kumar Javvadi
0960
Reply This Thread
up-rate
3
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in