What would be the next step in order to ask the user which of the numbers in this series of 30 he wants to see and prompts for an integer input - a number between 1 and 30 (inclusive)?
So if the user wants to see the fifth (5th) number of the Fibonacci series the user would input the integer 5 in response to the prompt.
public class MyFibonacci {
public static void main(String a[]) {
int febCount = 30;
int[] feb = new int[febCount];
feb[0] = 0;
feb[1] = 1;
for(int i=2; i < febCount; i++) {
feb[i] = feb[i-1] + feb[i-2];
}
for(int i=0; i< febCount; i++) {
System.out.print(feb[i] + " ");
}
}
}
Use a
Scanner
, or someInputStreamReader
to read the input from the console.Scanner
would be used in this way:Another option would be to use some reader like this:
and parse the required data from the output of the reader. Using
Scanner
will be simpler in most cases though.