- #1

- 596

- 49

## Homework Statement

Hello everyone, I am trying to write a java program that asks the user to input a number n, and the computer calculates the nth Fibonacci number. I am supposed to use a loop to calculate the problem.

My question is, how do I set up the loop to calculate the nth Fibonacci number? I know how to do all of the program except the loop.

## Homework Equations

I want to use the "for" loop.

## The Attempt at a Solution

import java.util.Scanner;

public class Assignment2 {

public static void main(String [] args) {

Scanner input = new Scanner(System.in);

System.out.print("Enter a number n in order to calculate the nth Fibonacci number: ");

int n = input.nextInt();

for(int i = 0; i;){}

System.out.println("The " + n + "th Fibonacci number is: ");

}

}