Sunday, October 16, 2011

Algoritma dan Pemrograman 3 (Tugas Java)

Membuat Deret Ganjil 

public class deretganjil {
public static void main(String[] args) {
int n;
for(n=1;n<30;n+=2)
System.out.print(" "+ n);
}
}

( Output : 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 )



Membuat Deret Fibonaci 

public class fibonanci {
    public static void main (String args[]){
        int a = 1;
        int b = 1;
        int c = 9;

        System.out.print(a + " ");
        while (b < c){// saat nilai b = 1 < c = 9
     System.out.print(a + " ");//print out nilai a
     a = a+b;
     b = a-b;
        }
    }

}


( Output : 1 1 2 3 5 8 13 21 34 )
»»  READMORE...