From 24978fdce1993c1c0567f479e7c8472af0877e03 Mon Sep 17 00:00:00 2001 From: maram934 Date: Thu, 31 Oct 2024 18:56:59 +0530 Subject: [PATCH] Create fibonacci --- Java/fibonacci | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Java/fibonacci diff --git a/Java/fibonacci b/Java/fibonacci new file mode 100644 index 0000000..45da4f4 --- /dev/null +++ b/Java/fibonacci @@ -0,0 +1,19 @@ +import java.util.*; + +public class fibonacci { + public static void main(String[]hg){ + Scanner sc = new Scanner(System.in); + int a=0; + int b=1; + int n = sc.nextInt(); + int sum=0; + while(n>0){ + sum+=a; + a = b; + b = sum; + n--; + } + System.out.println(sum); + sc.close(); + } +}