Source code dengan menggunakan fibonanci... disini saya membuat dengan menggunakan console, dengan bahasa pemrograman JAVA
souce code adalah
import java.io.*;
public class Fibonacci {
private int hitung(int index) {
if(index == 1 || index == 0) {
return index;
} else {
return hitung(index - 1) + hitung(index - 2);
}
}
private void tampilDeret(int index) {
for(int i = 0; i <= index; i++) {
int num = hitung(i);
System.out.print(num + " ");
}
}
public static void main(String[] args) {
Fibonacci fib = new Fibonacci();
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String numStr = "";
System.out.println("Deret Fibonacci");
System.out.print("Masukkan index: ");
try {
numStr = bf.readLine();
} catch(IOException e) {
System.out.println("Error...");
}
/* int hasil = fib.hitung(Integer.parseInt(numStr));
System.out.print("Bilangan Fibonacci pada index ke-" + numStr +
" adalah: ");
System.out.println(hasil);
*/
fib.tampilDeret(Integer.parseInt(numStr));
System.out.println();
}
}
All About JAvA Programming
Categories
- 2 (1)
- array (1)
- balok (1)
- binary (1)
- bukan prima (1)
- cari (1)
- demopassword (1)
- else (2)
- fibonanci (1)
- float (1)
- for (1)
- hitung (1)
- if (2)
- import (2)
- int (4)
- io (1)
- james gosling (1)
- java (2)
- java1 (1)
- java2 (1)
- javax (2)
- jcreator (1)
- Joptionpane (6)
- konversi (3)
- lebar (1)
- luas (2)
- null (1)
- oak (1)
- OOP (1)
- p.l.t (1)
- panjang (1)
- parseInt (1)
- password (1)
- piramid (1)
- prima (1)
- public (1)
- rekursif (1)
- return (1)
- search (1)
- searching (1)
- segitiga (1)
- showinputdialog (2)
- sisi (1)
- sun microsystems (1)
- swing (1)
- triangle (1)
- volume (1)
Blog Archive
Link List
About Me
Cari
rss
12.05
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar