arrays - Java Fibonacci series -
what next step in order ask user of numbers in series of 30 wants see , prompts integer input - number between 1 , 30 (inclusive)?
so if user wants see fifth (5th) number of fibonacci series user input integer 5 in response 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; < febcount; i++) { feb[i] = feb[i-1] + feb[i-2]; } for(int i=0; i< febcount; i++) { system.out.print(feb[i] + " "); } } }
use scanner, or inputstreamreader read input console. scanner used in way:
scanner scanner = new scanner(system.in); if(scanner.hasnextint()) int someint = scanner.nextint(); another option use reader this:
bufferedreader br = new bufferedreader(new inputstreamreader(system.in)); and parse required data output of reader. using scanner simpler in cases though.
Comments
Post a Comment