Home > Enterprise >  I ran this code but it didn't run on the console
I ran this code but it didn't run on the console

Time:12-26

#package loops;
import java.util.Scanner;

public class Fabbonacchi {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int a = 0;
        int b = 1;

        System.out.print(a   " ");
        System.out.print(b   " ");

        for (int i = 0; i < n - 2; i  ) {
            int c = a   b;
            System.out.print(c   " ");
            a = b;
            b = c;
        }
    }
}

I ran this code but its not running. I mean on the console ..

CodePudding user response:

Your code is running perfectly fine. Remember you suppose to add a integer on the console.

To get more guidance run like this, on the (for) statement line add:

System.out.print("Type the number\n" c   " ");

then type out the integer.

CodePudding user response:

You probably simply need to write some integer on the console and then you will see proper output on the console. First you created a Scanner object then assigned a input from console to n variable, everything after n initialization will run after you provide some value to n. So when you run the program what you get is empty console, write 10 for example and everything will be fine.

  •  Tags:  
  • java
  • Related