class relasi
{
private static BufferedReader input = new BufferedReader (new InputStreamReader(System.in));
public static void main(String[] args) throws Exception
{
System.out.println("Aplikasi Relasi Matematika Infomatika by Angga Erwin A");
System.out.print("Masukkan Banyak Himpunan A : ");
int x=Integer.parseInt(input.readLine());
int himpA [] = new int[x];
for(int i=0; i
{
System.out.print("Masukkan Elemen A ke-"+(i+1)+" :");
String a=input.readLine();
himpA[i]=Integer.parseInt(a);
}
System.out.print("Anggota Himpunan A = {");
for(int i=0;i
{
System.out.print(himpA[i]);
if(i!=x-1)
System.out.print(",");
}
System.out.println("}");
System.out.println();
System.out.print("Masukkan Banyak Himpunan B : ");
int y=Integer.parseInt(input.readLine());
int himpB [] = new int[y];
for(int j=0; j
{
System.out.print("Masukkan Elemen B ke-"+(j+1)+" :");
String b=input.readLine();
himpB[j]=Integer.parseInt(b);
}
System.out.print("Anggota Himpunan B = {");
for(int j=0; j
{
System.out.print(himpB[j]);
if(j!=y-1)
System.out.print(",");
}
System.out.println("}");
System.out.println();
System.out.println ("=======================");
System.out.println (" Jenis Relasi " );
System.out.println ("=======================");
System.out.println ("1. reflektif sederhana");
System.out.println ("2. simestris sederhana");
System.out.println ("3. transitif sederhana");
System.out.println ("=======================");
System.out.print ("Masukan Jenis Relasi yang diinginkan : ");
String c=input.readLine();
int pil=Integer.parseInt(c);
System.out.println();
switch (pil)
{
case 1:
//membuat relasi reflektif himpunan A dan himpunan B
System.out.print ("Relasi R = {");
for (int i=0; i
{
for (int j=0; j
{
if (himpA[i]==himpB[j])
{
System.out.print ("("+himpA[i]+","+himpB[j]+")");
if(j!=y-1)
System.out.print (",");
}
}
}
System.out.println ("}");
System.out.println ();
break;
case 2:
//membuat relasi simetris himpunan A dan himpunan B
System.out.print ("Relasi R = {");
for (int i=0; i
{
for (int j=0; j
{
if (himpA[i]!=himpB[j])
{
System.out.print ("("+himpA[i]+","+himpB[j]+")");
if(j!=y-1)
System.out.print (",");
}
}
if(i!=x-1)
System.out.print (",");
}
System.out.println ("}");
System.out.println ();
break;
case 3:
//membuat relasi transitif
System.out.print ("Relasi R = {");
for (int i=0; i
{
for (int j=0; j
{
if (himpA[i]!= himpB[j])
{
if (i%2!=0)
{
if (himpA[i]==0)
{
System.out.print ("("+himpA[i]+","+himpB[j]+")");
if(j!=y-1)
System.out.print (",");
}
}
else
{
if (j%2!=0)
{
System.out.print ("("+himpA[i]+","+himpB[j]+")");
if(j!=y-1)
System.out.print (",");
}
}
}
}
}
System.out.println ("}");
System.out.println ();
break;
default:
System.out.println ("Maaf,pilihannya gak ada dalam daftar..");
break;
}
}
}
semoga bisa membantu..
ah iya, listing ini ga bisa dipake dikarenakan adanya beberapa fungsi karakter melebur jadi bahasa HTML..==a
ReplyDeletenanti dibikin versi ralatnya deh..