bahasa java

PROGRAM BILANGAN PRIMA DAN FIBONACCI

public class Bilanganprima {
public static void main(String[] args) {
new Bilanganprima();
}
public Bilanganprima()
{
cetakPrima(100);
}
public void cetakPrima(int nRange)
{
boolean isPrima = false;
for (int i = 2; i <= nRange; i++)
{
if (i >= 2)
{
isPrima = true;
for (int j = 2; j < i; j++)
{
if (i % j == 0)
{
isPrima = false;
break;
}
}
}
if(isPrima)
{
System.out.print(i + ” “);
}
}
}
}

 

public class bilanganfibonacci {
public static void main (String [] args) {
int A=1;
int B=1;
System.out.print(A+” “);
while (B<100) {
System.out.print(B+” “);
B=A+B;
A=B-A;
}
}
}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: