0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Javaで書くフィボナッチ数列

Posted at

Javaで書くフィボナッチ数列

Javaを使ってフィボナッチ数列を生成するプログラムを作成しました。

コード

public class Fibonacci {
	public static void main(String[] args)
	{
		int f0,f1,f2;
		
		f0 = 0;
		f1 = 1;
		
		System.out.println(f0);
		
		while(f1 < 100000)
		{
			System.out.println(f1);
			
			f2 = f0 + f1;
			
			f0 = f1;
			
			f1 = f2;
		}
		
	}

}

結果

0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368
75025
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?