repl.it
@Brawn/

Mastery Project #3B Code #1

Java

Fibonacci Sequence

fork
loading
Files
  • Main.java
Main.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
/*
Name: Allan Abraham
Purpose: Prints out requested amount of numbers from
the Fibonacci Sequence. Has to be between 0 and 46,
because after that it reaches the 2 bil limit.
*/
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		System.out.println("How many numbers from the Fibonacci Sequence do you need?");
		System.out.println("Limit is 46");
		int need = input.nextInt();
		if(need <= 46 && need > 0){
			System.out.println("Thank you!");
			int uno = 0;
			int dos = 1;
			for(int count = 0; count < need; count++){
				int next = uno + dos;
				System.out.println(dos);
				uno = dos;
				dos = next;
			}
		}
		else{
			System.out.print("Please input a number that is between 0 and 46");
		}
	}
}
?