Tugas Java ( Algoritma Pemrograman 3)

04.15 Edit This 0 Comments »
Nama: Sinta Suciana Rahayu P.
Kelas: 2Kb01
NPM: 28110177





Program java bilangan ganjil...

coding:

public class deretganjil{
public static void main (String [] args){
for (int a=1;s<=24;s++) //nilai ganjil dari 1 -> 24
{

if (a==1) //mulai dari angka 1
{
System.out.print(a);} //hasil

else if (a%2==1){
System.out.print(", "+s);}}}} // pembatas nilai ","



outputnya : 1, 3, 5, 7, ... , 29


public class DeretFibonacci {

public static void main(String[] args) {
int r=0,s=1;
int z = 9;//ini menunjukkan jumlah deret fibonacci yg ingin ditampilkan
for (int y=1;y<=z;y++){
System.out.print(r+" ");
r=r+s;
s=r-s;
}
}
}



outputnya: 0 1 1 2 3 5 8 13 21