Home > Java Programming, Source Code > Menghitung Luas Persegi

Menghitung Luas Persegi


package SL275;

/**
*
* @author GW_SBY
*/
public class Persegi {

double panjang;
double lebar;
double luas;

void hitung() {
luas = panjang * lebar;
System.out.println(“Luas Persegi = ” + luas + “cm3″);
}
}

class luas_persegi {

public static void main(String args[]) {
Persegi a = new Persegi();
Persegi b = new Persegi();

a.panjang = 20;
a.lebar = 10;
System.out.println(“Persegi A :”);
System.out.println(“Panjang = ” + a.panjang + “cm”);
System.out.println(“Lebar = ” + a.lebar + “cm”);
a.hitung();

b.panjang = 30;
b.lebar = 20;
System.out.println(“Persegi B :”);
System.out.println(“Panjang = ” + b.panjang + “cm”);
System.out.println(“Lebar = ” + b.lebar + “cm”);
b.hitung();
}
}

About these ads
  1. gobang
    February 2, 2010 at 3:14 am

    mantap gan…
    sundul.. sundul…

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: