Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fibonacci;
- import java.util.Scanner;
- /**
- *
- * @author Aidan
- */
- public class Fibonacci {
- static {
- renew();
- }
- private static void renew() {
- input = new Scanner(System.in);
- }
- private static Scanner input;
- public static void main(String[] args) {
- Integer a = 0, b = 1, c = 0, upper;
- do {
- System.out.print("Enter the number to approch: ");
- try {
- upper = input.nextInt();
- } catch (Exception e) {
- upper = 0;
- }
- renew();
- } while (upper <= 0);
- do {
- c = a + b;
- a = b;
- b = c;
- //
- System.out.print(a + " ");
- System.out.flush();
- } while (c < upper);
- System.out.println("\nReached " + a + '.');
- System.out.flush();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement