I am trying to make a Fibonacci sequence program to display up to the nth term(only positive numbers).
For some reason it doesn't seem to work.
import java.util.Scanner;
/**
*
* @author Toby
*/
public class Fabonnacci {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Enter the trem of the fabonacci sequence: ");
Scanner input = new Scanner(System.in);
int term = input.nextInt();
int x =0;
int y =0;
int output =0;
int first3[] = new int[4];
first3[0]=0;
first3[1]=1;
first3[2]=1;
first3[3]=2;
for(int i = 0;i<=term;i++){
if(term<=3){
output=first3[term];
System.out.print(first3[term]);
}else{
if(i==0){
System.out.print("0,1,1,2");
x=1;
y=2;
System.out.print("," + (x+y));
}else if(x>y){
y+=x;
System.out.print(","+ y);
}else if(y>x){
x+=y;
System.out.print(","+ y);
}
}
}
}
}
NOTE - this is not a school project. I am teaching myself java.