Listing Program
import java.io.*;
import java.io.*;
class fungsi
{
private static BufferedReader input=new BufferedReader (new InputStreamReader(System.in));
public static void main(String[]args)throws Exception
{
//himpunan A
System.out.print("Banyak Himpunan 'A' = ");
int x=Integer.parseInt(input.readLine());
int himpA[]=new int[x];
for (int i=0;i {
System.out.print("Elemen 'A' ke-"+(i+1)+" :");
String a=input.readLine();
himpA[i]=Integer.parseInt(a);
}
System.out.print("A={");
for (int i=0;i {
System.out.print(himpA[i]);
if (i!=x-1)
System.out.print(",");
}
System.out.println("}");
//himpunan B
System.out.print("Banyak Himpunan 'B' = ");
int y=Integer.parseInt(input.readLine());
int himpB[]=new int[y];
for (int j=0;j {
System.out.print("Elemen 'B' ke-"+(j+1)+" :");
String b=input.readLine();
himpB[j]=Integer.parseInt(b);
}
System.out.print("B={");
for (int j=0;j {
System.out.print(himpB[j]);
if (j!=y-1)
System.out.print(",");
}
System.out.println("}");
// Fungsi
System.out.print("F(A->B)={");
if (x<=y)
for (int i=0;i {
for (int j=i;j<=i;j++)
System.out.print("("+himpA[i]+","+himpB[j]+")");
if (i!=x-1)
System.out.print(",");
}
else
{
for (int i=0;i {
for (int j=i;j<=i;j++)
System.out.print("("+himpA[i]+","+himpB[j]+")");
System.out.print(",");
}
for (int i=y;i {
for (int j=(i-y);j<=(i-y);j++)
System.out.print("("+himpA[i]+","+himpB[j]+")");
if (i!=x-1)
System.out.print(",");
}
}
System.out.print("invers={");
if (x<=y)
for (int i=0;i {
for (int j=i;j<=i;j++)
System.out.print("("+himpB[j]+","+himpA[i]+")");
if (i!=x-1)
System.out.print(",");
}
else
{
for (int i=0;i {
for (int j=i;j<=i;j++)
System.out.print("("+himpB[j]+","+himpA[i]+")");
System.out.print(",");
}
for (int i=y;i {
for (int j=(i-y);j<=(i-y);j++)
System.out.print("("+himpB[j]+","+himpA[i]+")");
if (i!=x-1)
System.out.print(",");
}
}
}
}
{
private static BufferedReader input=new BufferedReader (new InputStreamReader(System.in));
public static void main(String[]args)throws Exception
{
//himpunan A
System.out.print("Banyak Himpunan 'A' = ");
int x=Integer.parseInt(input.readLine());
int himpA[]=new int[x];
for (int i=0;i {
System.out.print("Elemen 'A' ke-"+(i+1)+" :");
String a=input.readLine();
himpA[i]=Integer.parseInt(a);
}
System.out.print("A={");
for (int i=0;i {
System.out.print(himpA[i]);
if (i!=x-1)
System.out.print(",");
}
System.out.println("}");
//himpunan B
System.out.print("Banyak Himpunan 'B' = ");
int y=Integer.parseInt(input.readLine());
int himpB[]=new int[y];
for (int j=0;j {
System.out.print("Elemen 'B' ke-"+(j+1)+" :");
String b=input.readLine();
himpB[j]=Integer.parseInt(b);
}
System.out.print("B={");
for (int j=0;j {
System.out.print(himpB[j]);
if (j!=y-1)
System.out.print(",");
}
System.out.println("}");
// Fungsi
System.out.print("F(A->B)={");
if (x<=y)
for (int i=0;i {
for (int j=i;j<=i;j++)
System.out.print("("+himpA[i]+","+himpB[j]+")");
if (i!=x-1)
System.out.print(",");
}
else
{
for (int i=0;i {
for (int j=i;j<=i;j++)
System.out.print("("+himpA[i]+","+himpB[j]+")");
System.out.print(",");
}
for (int i=y;i {
for (int j=(i-y);j<=(i-y);j++)
System.out.print("("+himpA[i]+","+himpB[j]+")");
if (i!=x-1)
System.out.print(",");
}
}
System.out.print("invers={");
if (x<=y)
for (int i=0;i {
for (int j=i;j<=i;j++)
System.out.print("("+himpB[j]+","+himpA[i]+")");
if (i!=x-1)
System.out.print(",");
}
else
{
for (int i=0;i {
for (int j=i;j<=i;j++)
System.out.print("("+himpB[j]+","+himpA[i]+")");
System.out.print(",");
}
for (int i=y;i {
for (int j=(i-y);j<=(i-y);j++)
System.out.print("("+himpB[j]+","+himpA[i]+")");
if (i!=x-1)
System.out.print(",");
}
}
}
}
LOGIKA PROGRAM
Dalam praktek kali ini kita akan membahas program java tentang fungsi himpunan,Fungsi adalah relasi khusus yang memasangkan setiap anggota ,atau relasi khusus yang memasangkan satu anggota dengan satu anggota lain.
Saya akan menjelaskan maksud dari sebuah program diatas yang telah saya buat dihalaman sebelumnya,
class fungsihimpunan maksudnya adalah mendeklarasikan nama dari kelas adalah fungsi himpunan
private static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws Exception maksudnya adalah mendeklarasikanvariabel bernama data input,dengan tipe class BufferedReader
System.out.print("banyak himpunan A: "); akan mencetak tulisan “himpunan A”
int x = Integer.parseInt(input.readLine()); nilai akan dimasukkan dan akan dibaca ketika program dijalankan
int himpA[] = new int[x];arti\nya nilai dari himpA adalah nilai yang baru akan dimasukkan
for (int i=0; i
for (int i=0; i
{
for (int j=1; j<=i; j++)
System.out.print("{"+himpA[i]+","+himpB[j]+"}");
System.out.print(",");
}
for (int i=y; i
{
for (int j=(i-y); j<=(i-y); j++)
System.out.print("{"+himpA[i]+","+himpB[j]+"}");
if (i!=x-1)
System.out.print(",");
}
}
System.out.print("}");
}
}
Diatas yang merupakan rumus dari fungsi himpunan diprogram ini, himpA[i] akan dipasangkan dengan himpB[i] sesuai dengan urutan kesampingnya ,dan setiap anggota himpA masing-masing dipasangkan ke anggoto himpB dan masing-masing hanya satu pasangan tidak boleh lebih.
Post a Comment