TUGAS
ALGORITMA DAN PEMROGRAMAN

Disusun Oleh
:
HERI PURNAMA
125410101
TI 2
Sekolah Tinggi Manajemen Informatika dan Komputer
AKAKOM
Yogyakarta
2012
1.Membuat
Prog.rekursif FIBONACCI .output (0 1 2 3 5 8 13……)
INPUT
public class Fibonacci69{
public static long fib(long a) {
if ((a== 0) || (a== 1))
return a;
else
return fib(a-1) + fib(a -2);
}
public static void main(String[] args) {
for (int b= 0;b<= 10;b++)
System.out.print(fib(b));
System.out.println("");
}
}
OUTPUT

2.Mengubah
Pro.perulangan FOR mebjadi WHILE dan Do…WHILE
a).Prog
FOR kalang
INPUT
import
java.util.Scanner;
public class
UlangForKalang1
{
public static
void main(String args[]){
Scanner masuk =
new Scanner(System.in);
int i,j,n;
System.out.print("n=
");
n =
masuk.nextInt();
for
(i=1;i<=n;i++)
{
for
(j=1;j<=i;j++)
{
System.out.print(j);
}
System.out.println("
");
}
}
}
OUTPUT

b).
Prog WHILE kalang
INPUT
import
java.util.Scanner;
public class
WhileKalang
{
public static
void main(String args[]){
Scanner masuk =
new Scanner(System.in);
int i,j,n;
System.out.print("n=
");
n =
masuk.nextInt();
i=1;
while (i<=n)
{
j=1;
while (j<=i)
{
System.out.print(j);
j++;
}
System.out.println("
");
i++;
}
}
}
OUTPUT

C). Prog do…….WHILE kalang
INPUT
import
java.util.Scanner;
public class
DoKalang
{
public static void main(String
args[]){
Scanner masuk = new
Scanner(System.in);
int i,j,n;
System.out.print("n=
");
n = masuk.nextInt();
i=1;
do
{
j=1;
do
{
System.out.print(j);
j++;
}while
(j<=i);
System.out.println("");
i++;
}while (i<=n);
}
}
OUTPUT

3.Membuat
Prog.menggunakan method untuk menghitung luas dan keliling lingkaran
INPUT
public class
lingkaran{
public float luas(){
int r=5;
float phi=3.14f;
return(phi*r*r);}
public float keliling(){
int r=2;
float phi=3.14f;
return(2*phi*r);}
public static
void main(String args[]){
lingkaran obyek=new lingkaran();
System.out.println("Hasil
pemanggilan method luas lingkaran");
System.out.print("");
System.out.println(obyek.luas());
System.out.println("Hasil
pemanggilan method keliling lingkaran");
System.out.print("");
System.out.println(obyek.keliling());
}
}
OUTPUT

7BAC0259AB
ReplyDeleteMany entrepreneurs are looking for innovative ways to enhance their product designs, and one popular method is using dtf transfer technology. This process allows for vibrant, detailed prints to be applied to various surfaces, making customization easier than ever. With its durability and ease of use, dtf transfer is quickly becoming a favorite among small business owners and hobbyists alike. Ultimately, it offers a cost-effective solution to create professional-quality results.