Computer Science, asked by akshatmalik4460, 1 year ago

write a program in java to print the fibonacci series upto 10 terms

Answers

Answered by ganrocks
10

Answer:

import java.util.Scanner;

public class Fibonacci

{

public static void main(String[] args)

{

int n, a = 0, b = 0, c = 1;

Scanner s = new Scanner(System.in);

System.out.print("Enter value of n:");

n = s.nextInt();

System.out.print("Fibonacci Series:");

for(int i = 1; i <= n; i++)

{

a = b;

b = c;

c = a + b;

System.out.print(a+" ");

}

}

}

Answered by diyanshah2301
0

Answer:class Main {

 public static void main(String[] args) {

   int n = 10, firstTerm = 0, secondTerm = 1;

   System.out.println("Fibonacci Series till " + n + " terms:");

   for (int i = 1; i <= n; ++i) {

     System.out.print(firstTerm + ", ");

     // compute the next term

     int nextTerm = firstTerm + secondTerm;

     firstTerm = secondTerm;

     secondTerm = nextTerm;

   }

 }

}

Explanation:

Similar questions