Home > Java > javaTutorial > body text

How to implement Fibonacci Sequence in JShell in Java 9?

WBOY
Release: 2023-09-10 19:01:17
forward
632 people have browsed it

如何在Java 9的JShell中实现斐波那契数列?

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>
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template