Hallo guys... nih gue mau berbagi code untuk membuat perhitungan bangun datar dalam java. Gue pake persegi,persegi panjang, segituga, dan lingkaran. Oke guys mari disimak codenya.
Luas Persegi
Codenya
package luaspersegi;public class LuasPersegi {
public static void main(String[] args) {
int s=5, luas;
luas=s*s;
System.out.println("====Perhitungan Luas Persegi====");
System.out.println("*Diketahui :");
System.out.println("Sisi\t= "+s+"cm");
System.out.println("*Rumus :");
System.out.println("Luas\t= SxS");
System.out.println("\t= "+s+"cm x "+s+"cm");
System.out.println("\t= "+luas+"cm");
}
}
Outputnya
Luas Persegi Panjang
Codenya
package luaspersegi;
public class LuasPersegi {
public static void main(String[] args) {
int p=5,l=4, luas;
luas=p*l;
System.out.println("====Perhitungan Luas Persegi Panjang====");
System.out.println("*Diketahui :");
System.out.println("Panjang\t= "+p+"cm");
System.out.println("Lebar\t= "+l+"cm");
System.out.println("*Rumus :");
System.out.println("Luas\t= PxL");
System.out.println("\t= "+p+"cm x "+l+"cm");
System.out.println("\t= "+luas+"cm");
}
}
public class LuasPersegi {
public static void main(String[] args) {
int p=5,l=4, luas;
luas=p*l;
System.out.println("====Perhitungan Luas Persegi Panjang====");
System.out.println("*Diketahui :");
System.out.println("Panjang\t= "+p+"cm");
System.out.println("Lebar\t= "+l+"cm");
System.out.println("*Rumus :");
System.out.println("Luas\t= PxL");
System.out.println("\t= "+p+"cm x "+l+"cm");
System.out.println("\t= "+luas+"cm");
}
}
Outputnya
Luas Segitiga
Codenya
package LuasSegitiga;
public class LuasSegitiga {
public static void main(String[] args) {
double a=5, t=3, luas;
luas=0.5*a*t;
System.out.println("====Hasil Perhitungan Luas Segitiga====");
System.out.println("Alas\t= "+a+"cm");
System.out.println("Tinggi\t= "+t+"cm");
System.out.println("Luas\t= 0.5 x a x t");
System.out.println("\t= 0.5 x "+a+"cm x "+t+"cm");
System.out.println("\t= "+luas+"cm");
}
}
public class LuasSegitiga {
public static void main(String[] args) {
double a=5, t=3, luas;
luas=0.5*a*t;
System.out.println("====Hasil Perhitungan Luas Segitiga====");
System.out.println("Alas\t= "+a+"cm");
System.out.println("Tinggi\t= "+t+"cm");
System.out.println("Luas\t= 0.5 x a x t");
System.out.println("\t= 0.5 x "+a+"cm x "+t+"cm");
System.out.println("\t= "+luas+"cm");
}
}
Outputnya
Codenya
package LuasLingkaran;
public class LuasLingkaran {
public static void main(String[] args) {
double phi=3.14, r=3, luas;
luas=phi*r*r;
System.out.println("====Hasil Perhitungan Luas Lingkaran====");
System.out.println("Phi\t= "+phi+"cm");
System.out.println("r\t= "+r+"cm");
System.out.println("Luas\t= phi x r x r");
System.out.println("\t= "+phi+"cm x "+r+"cm x "+r+"cm");
System.out.println("\t= "+luas+"cm");
}
}
public class LuasLingkaran {
public static void main(String[] args) {
double phi=3.14, r=3, luas;
luas=phi*r*r;
System.out.println("====Hasil Perhitungan Luas Lingkaran====");
System.out.println("Phi\t= "+phi+"cm");
System.out.println("r\t= "+r+"cm");
System.out.println("Luas\t= phi x r x r");
System.out.println("\t= "+phi+"cm x "+r+"cm x "+r+"cm");
System.out.println("\t= "+luas+"cm");
}
}
Outputnya
Nah ittu tadi guys code dan outputannya semoga bermanfaat, sekian terima kasih.