Fibonacci series using java

I wrote this code to calculate Fibonacci numbers by specifying the size. The results are correct, however the one thing that concerns me is the negative sign for some numbers in the larger range of size input.
here is the code

import java.util.Scanner;

public class FibonacciSeries {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int a, c = 0;
        int result = 0;
        int b = 1;

        Scanner scan = new Scanner(System.in);
        System.out.println("Enter the Number to display Fibonacci Series");
        a = scan.nextInt();

        System.out.println("Fibonacci Seriers is as follows");


        for (int i = 1; i <= a; i++) {
            System.out.print(" "+result+" ");
            result = c + b;
            b = c;
            c = result;

        }

    }

}

As previously said, this function calculates fibonacci numbers by selecting the size. I read the article about it here according to that findings are right however the one thing that bothers me is the negative sign for some values in the greater range of size input.

1- I couldn’t identify a mistake in the code; how can I remove the negative values from the output?
2- Why are there positive values following certain negative values? 3- The first negative value is -1323752223, followed by a positive number.

Thank you very much.

1 Like