1.Apa yang kalian ketahui tentang fungsi
2.Jelaskan tentang fungsi satu-satu dan fungsi pada
LA:
import java.io.*;
class relasiLA
{
private static BufferedReader input = new BufferedReader (new InputStreamReader(System.in));
public static void main(String[] args) throws Exception
{
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.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(himpA[j]);2
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 b=input.readLine();
int pil=Integer.parseInt(b);
System.out.println();
switch (pil)
{
case 1:
//membuat relasi reflektif himpunan A
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
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 (j%2==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 ("Pilihan tak ada dalam daftar!!");
break;
}
}
}
ka, soal LP no 2 itu fungsi pada apa ka??
BalasHapus