Nama : Delwyn Antrayasa
npm : 21110775
kelas : 2 KB 01
1. Membuat Deretganjil : 1,3,5,7,9,13, ....
Programnya seperti :
public class DeretGanjil
{
public static void main (String[]args)
{
int a,b;
b = 15;
for(a=1;a<b;x++)
{
if(a==1)
System.out.print(a);
else
System.out.print(","+a);
a=a+1;
}
}
}
Output: 1,3,5,7,9,11,13
2. Membuat Baris : 1,1,2,3,5,8,13 ....
public class DeretFabonanci
{
public static void main(String[] args)
{
int x=0,y=1;
int n = 10; // DeretFabonanci
for (int i=1;i<=n;i++)
{
System.out.print(x+" ");
x=x+y;
y=x-y;
}
}
}
output : 1,1,2,3,5,8,13, ...
npm : 21110775
kelas : 2 KB 01
1. Membuat Deretganjil : 1,3,5,7,9,13, ....
Programnya seperti :
public class DeretGanjil
{
public static void main (String[]args)
{
int a,b;
b = 15;
for(a=1;a<b;x++)
{
if(a==1)
System.out.print(a);
else
System.out.print(","+a);
a=a+1;
}
}
}
Output: 1,3,5,7,9,11,13
2. Membuat Baris : 1,1,2,3,5,8,13 ....
public class DeretFabonanci
{
public static void main(String[] args)
{
int x=0,y=1;
int n = 10; // DeretFabonanci
for (int i=1;i<=n;i++)
{
System.out.print(x+" ");
x=x+y;
y=x-y;
}
}
}
output : 1,1,2,3,5,8,13, ...
Tidak ada komentar:
Posting Komentar