Lingkaran.java



// Lingkaran.java
// ditulis : Wahyudin
// 31 Maret 2007
import java.text.DecimalFormat;
import javax.swing.JOptionPane;

public class Lingkaran {

public static void main(String[] args)
{
String sD; // input Diameter Lingkaran
String sr; // input jari-jari
String sL; // input Luas Lingkaran
String sK; // input Keliling Lingkaran
String Hasil;

double pi = 3.14159;
double D, r, L, K;

sD = JOptionPane.showInputDialog("Masukkan Diameter Lingkaran",0);
sr = JOptionPane.showInputDialog("Masukkan Jari-jari Lingkaran",0);
sL = JOptionPane.showInputDialog("Masukkan Luas Lingkaran",0);
sK = JOptionPane.showInputDialog("Masukkan Keliling Lingkaran",0);

D = Double.parseDouble(sD);
r = Double.parseDouble(sr);
L = Double.parseDouble(sL);
K = Double.parseDouble(sK);

Hasil = "Diketahui ";

if ( D > 0 )
{
r = D / 2;
L = pi * r * r;
K = 2 * pi * r;
Hasil = Hasil + "Diameter Lingkaran = "+ D +"\n"+"Maka dihasilkan : \n\n"+"Jari-jari = " + r + "\n" + "Luar Lingkaran = " + L + "\n"+"Keliling Lingkaran = "+ K;
}
if ( r > 0 )
{
D = r * 2;
L = pi * r * r;
K = 2 * pi * r;
Hasil = Hasil + "Jari-jari Lingkaran = "+ r +"\n"+"Maka dihasilkan : \n\n"+"Diameter = " + D + "\n" + "Luar Lingkaran = " + L + "\n"+"Keliling Lingkaran = "+ K;
}
if ( L > 0 )
{
r = L / pi;
D = r * 2;
L = pi * r * r;
K = 2 * pi * r;
Hasil = Hasil + "Jari-jari Lingkaran = "+ r +"\n"+"Maka dihasilkan : \n\n"+"Diameter = " + D + "\n" + "Luar Lingkaran = " + L + "\n"+"Keliling Lingkaran = "+ K;
}

JOptionPane.showMessageDialog(null, Hasil, "Lingkaran", JOptionPane.PLAIN_MESSAGE);
System.exit(0);
}
}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s