import java.util;
import java.io.*;
class Relasi
{
public static void main ( String [] args ) throws Exception
{
Scanner input = new Scanner(System.in);
int anggotaA;
int anggotaB;
//masukkan banyaknya Anggota dan Elemennya
System.out.print("\nmasukan Banyaknya AnggotaA : ");
anggotaA = input.nextInt();
int [] a = new int [anggotaA];
System.out.println("Masukkan AnggotaA : ");
for(int i=0 ; i <= anggotaA - 1 ; i++)
{
int L = i + 1;
System.out.print("Elemen ke-["+L+"] :");
a[i] = input.nextInt();
}
//masukkan elemen AnggotaB
System.out.print("\nmasukkan banyaknya AnggotaB : ");
anggotaB = input.nextInt();
int [] b = new int [anggotaB];
System.out.println("Masukkan AnggotaB : ");
for(int i=0 ; i <= anggotaB - 1 ; i++)
{
int L = i + 1;
System.out.print("Elemen ke-["+L+"] :");
b[i] = input.nextInt();
}
System.out.println("\n");
//tampil anggotaA
System.out.print("Anggota Himpunan A = { ");
for(int i=0;i<=anggotaA - 1;i++){
System.out.print(a[i]+" ");
}
System.out.println("}");
//tampil anggotaB
System.out.print("Anggota Himpunan B = { ");
for(int i=0;i<=anggotaB - 1 ;i++){
System.out.print(b[i]+ " ");
}
System.out.println("}");
//jumlah kedua anggota
int jumlahAB = anggotaA + anggotaB;
//inputkan relasi Antara Anggota A dan B
String[] e = new String[jumlahAB];
System.out.print("masukkan banyaknya relasi [ <= "+jumlahAB+" ] : " );
int banyak = input.nextInt();
char[] f = new char[banyak];
char[] g = new char[banyak];
System.out.println("inputkan dengan cara A,B ");
DataInputStream bl = new DataInputStream(System.in);
for(int i=0;i<=banyak-1;i++)
{
e[i] = bl.readLine();
}
//mengambil karakter
try{
for(int i=0;i<=banyak-1;i++)
{
e[i].getChars(0,1,f,i);
e[i].getChars(2,3,g,i);
}
boolean cek = true;
for(int i=0;i<=banyak-1;i++)
{
for(int x=0;x<=i;x++)
{
if(f[i]!=a[x])
{
cek = false;
}
else
if(g[i]!=b[x])
{
cek= false;
}
}
}
if(cek==false)
{System.out.println("Out Of Range");}
else
{System.out.println("\n");}
}
catch(Exception ex){ System.out.println("\n");}
//Range
System.out.print("\nRange = { ");
for(int i=0;i<=banyak-1;i++)
{
System.out.print(g[i]+" ");
}
System.out.println("}");
//domain
System.out.print("Domain = { ");
for(int i=0;i<=anggotaA-1;i++){
System.out.print(a[i]+" ");
}
System.out.println("}");
//invers
System.out.print("Invers = { ");
for(int n=0;n<=banyak-1;n++)
{
System.out.print("{"+g[n] +","+ f[n]+"}");
}
System.out.print(" }\n\n");
}
}
Tidak ada komentar:
Posting Komentar