Home / Pemrograman / JAVA / Belajar JAVA – Deret Bilangan Fibonacci

Belajar JAVA – Deret Bilangan Fibonacci

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package menghitungfibonacci;

/**
*
* @author eko rudiawan
*/
import java.io.*;

public class MenghitungFibonacci {

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
// TODO code application logic here
BufferedReader dataInput = new BufferedReader(new InputStreamReader(System.in));
String input;
int banyakBilangan = 0;
int a = 0;
int b = 1;
int c;
int i;
System.out.println("Bilangan Fibonacci");
System.out.print("Masukkan banyak bilangan = ");
try {
input = dataInput.readLine();
banyakBilangan = Integer.parseInt(input);
} catch (NumberFormatException error) {
System.out.println("Error !!");
}
System.out.print("Bilangan Fibonacci = " + a + " " + b + " ");
for (i = 0; i < banyakBilangan - 2; i++) {
c = a + b;
System.out.print(c + " ");
a = b;
b = c;
}
System.out.println("");
}
}

Tampilan Program

About Eko Rudiawan

Seorang lelaki yang punya ketertarikan dengan dunia elektronika dan robot yang saat ini sedang serius belajar tentang dunia bisnis dan internet marketing. My dream to be success technopreneur

Check Also

Searching Algoritm Java

Algoritma Searching Data Menggunakan Bahasa Java

Algoritma Searching Data /* * To change this template, choose Tools | Templates * and …

Leave a Reply

Your email address will not be published. Required fields are marked *

4 + 17 =