-
Notifications
You must be signed in to change notification settings - Fork 56
/
fibonacci.java
44 lines (32 loc) · 937 Bytes
/
fibonacci.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Program to print fibonacci series followed by giver number by user...
import java.util.Scanner;
public class fibonacci {
static int fib(int no)
{
if(no <= 1) {
return no;
}
else {
return fib(no - 1) + fib(no - 2);
}
}
//-------------------MAIN------------------------
public static void main(String[] args) {
Scanner inp = new Scanner(System.in);
while(true){
System.out.print("Enter Number : ");
int no = inp.nextInt();
int stop = 000;
if(no == stop) { // If user enter 000 process will stop..
break;
}
else {
for (int i = 0; i < no; i++) {
System.out.print(fib(i) + " ");
}
System.out.println(" ");
}
}
}
}
//exit is a string , but we are taking input as integer ( int no = inp.nextInt(); ) , how to break while loop ?