Dibawah ini merupakan beberapa contoh program menggunakan Method.
public class MahasiswaTeknik
{
public static void main (String[] args)
{
MahasiswaTekhnik MT=new MahasiswaTekhnik();
MT.setNamaNIP("Driyanto Saputro",1000);
MT.setJUR("Teknik Informatika");
MT.tampilkan();
}
}
class MahasiswaTekhnik
{
static String JUR;
private int NIP;
private String Nama;
void setNamaNIP(String n, int m)
{
Nama=n;
NIP=m;
}
void setJUR(String s)
{
JUR=s;
}
void tampilkan()
{
System.out.println("NIP = "+NIP);
System.out.println("NAMA = "+Nama);
System.out.println("JURUSAN = "+JUR);
}
}
{
public static void main (String[] args)
{
MahasiswaTekhnik MT=new MahasiswaTekhnik();
MT.setNamaNIP("Driyanto Saputro",1000);
MT.setJUR("Teknik Informatika");
MT.tampilkan();
}
}
class MahasiswaTekhnik
{
static String JUR;
private int NIP;
private String Nama;
void setNamaNIP(String n, int m)
{
Nama=n;
NIP=m;
}
void setJUR(String s)
{
JUR=s;
}
void tampilkan()
{
System.out.println("NIP = "+NIP);
System.out.println("NAMA = "+Nama);
System.out.println("JURUSAN = "+JUR);
}
}
Output :
public class Menu
{
public static void main(String[] args)
{
garis();
System.out.println(" Menu Utama");
garis();
System.out.println(" 1. Luas Segitiga");
System.out.println(" 2. Luas Lingkaran");
System.out.println(" 3. Luas Persegi panjang");
System.out.println(" 4. Luas Kotak");
garis();
}
static void garis()
{
System.out.println("----------------------------");
}
}
{
public static void main(String[] args)
{
garis();
System.out.println(" Menu Utama");
garis();
System.out.println(" 1. Luas Segitiga");
System.out.println(" 2. Luas Lingkaran");
System.out.println(" 3. Luas Persegi panjang");
System.out.println(" 4. Luas Kotak");
garis();
}
static void garis()
{
System.out.println("----------------------------");
}
}
Output :
public class TugasNo4
{
public static void main(String[] args)
{
garis();
System.out.println("NO\tNIP\tNAMA\t\tJURUSAN");
garis();
System.out.println(" ");
System.out.println(" ");
System.out.println(" ");
garis();
}
static void garis()
{
System.out.println("-------------------------------------------------");
}
}
{
public static void main(String[] args)
{
garis();
System.out.println("NO\tNIP\tNAMA\t\tJURUSAN");
garis();
System.out.println(" ");
System.out.println(" ");
System.out.println(" ");
garis();
}
static void garis()
{
System.out.println("-------------------------------------------------");
}
}
Output :
0 komentar:
Posting Komentar