diff --git a/fibonacci.java b/fibonacci.java new file mode 100644 index 0000000..ba8b05b --- /dev/null +++ b/fibonacci.java @@ -0,0 +1,21 @@ +import java.io.*; + +class fibonacci { + public static void main(String[] args) throws IOException { + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + System.out.println("enter number of terms"); + int n = Integer.parseInt(in.readLine()); + int i = 0, j = 1, nextTerm; + System.out.println("Fibonacci series is "); + for (int c = 0; c < n; c++) { + if (c <= 1) + nextTerm = c; + else { + nextTerm = i + j; + i = j; + j = nextTerm; + } + System.out.println(nextTerm); + } + } +} \ No newline at end of file