Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Fibonacci2 {
- public static void main(String[] args) {
- System.out.println("Please enter the number of Fibonacci numbers to display: ");
- Scanner s = new Scanner(System.in);
- Integer n = s.nextInt();
- int a = 0; //a = x
- int b = 1; // b = i
- System.out.print(a + ", ");
- System.out.print(b);
- for(int i=1; i < n-1; i++) {
- System.out.print(", " + b);
- a = b - a;
- b = b + a;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement