Q:

Java Program to display the fibonacci series based on the user input

0

Java Program to display the fibonacci series based on the user input

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;
public class demo1 
{
 public static void main(String[] args) 
 {
  int count, num1 = 0, num2 = 1;
  System.out.println("How may numbers you want in the series:");
  Scanner input = new Scanner(System.in);
  count = input.nextInt();
  input.close();
  System.out.print("Fibonacci Series of "+count+" numbers:");

  int a=1;
  while(a<=count)
  {
   System.out.print(num1+" ");
   int sum = num1 + num2;
   num1 = num2;
   num2 = sum;
   a++;
  }
 }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now