Home >Java >javaTutorial >How to implement Fibonacci Sequence in JShell in Java 9?
JShell is a java shell tool introduced in Java 9 that allows us to execute Java code and print the results immediately. It is a REPL (Read-Evaluate-Print-Loop) tool run from the command line prompt.
If a number is Fibonacci Sequence, if each subsequent number is the sum of the two previous numbers.
In the example below, we can implement the Fibonacci sequenceseries in the JShell tool.
<strong>C:\Users\User\>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> int x=0, y=1, z=0, count=5; x ==> 0 y ==> 1 z ==> 0 count ==> 5 jshell> { ...> System.out.println(x+"\n"+y); ...> for(int i=0; i<count; i++) {</strong> <strong>...> x=y; y=z;</strong> <strong>...> z = x+y;</strong> <strong>...> System.out.println(z); ...> } ...> } 0 1 1 2 3 5 8 jshell></strong>
The above is the detailed content of How to implement Fibonacci Sequence in JShell in Java 9?. For more information, please follow other related articles on the PHP Chinese website!