Blogroll

Monday, October 17, 2011

Algoritma dan Pemrograman 3

public class tugas1{

public static void main(String [] args){


dt e=new dt();
e.d=10;
e.Deret();

}}


class dt{

int d,a;
void Deret(){
for(a=1;a {
if(a==1)
System.out.print(a);
else

System.out.print(",");

a=a+1;

}

}
}
public class tugas2{

public static void main(String [] args){

dt e=new dt();
e.Deret();

}}


class dt{

int SK=10; //sampai suku ke 10
int x=0,y=0,z=0;

void Deret(){


for(int i=1;i<=SK;i++){ //perintah looping sampai suku ke 10


if(a < i && i==1)
{
System.out.print(i);
x=i;
}

if(y < x)

{
z=x+y;
System.out.print(", "+z);
y=z;//perubahan nilai y
}

if(i>2)

{
z=x+y;
System.out.print(", "+z);
x=y; //perbarui nilai x
y=z; //perbarui nilai y
}
}
}
}

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | GreenGeeks Review