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");
}
}
November 15, 2010
listing program matif KARTESIUS
import java.util.Scanner;
public class kartesius
{
public static void main ( String [] args)
{
Scanner input = new Scanner(System.in);
int[] a = new int [10];
int[] b = new int [10];
int anggotaA;
int anggotaB;
//masukkan banyaknya anggota a
do
{
System.out.print("Masukkan Banyaknya Himpunan A ( x<10 ) : ");
anggotaA = input.nextInt();
if(anggotaA > 10)
System.out.println("\n nilai harus \"x < 10\"\n");
}
while (anggotaA > 10);
//masukkan banyaknya anggota b
do
{
System.out.print("Masukkan Banyaknya Himpunan B ( y<10 ) : ");
anggotaB = input.nextInt();
if(anggotaB > 10)
System.out.println("\n nilai harus \"y < 10\"\n");
}
while (anggotaB > 10);
//masukkan elemen a
System.out.println("\nMasukkan Elemen Anggota A");
for(int i = 0 ; i <= anggotaA - 1 ; i++)
{
int z= i + 1;
System.out.print("\nElemen ke-["+z+"] : ");
a[i] = input.nextInt();
}
System.out.println("\n");
//masukkan elemen b
System.out.println("\nMAsukkan Anggota B");
for( int w = 0 ; w <= anggotaB - 1 ; w++)
{
int L = w + 1;
System.out.print("\nElemen ke-["+L+"] : ");
b[w] = input.nextInt();
}
System.out.println("\n");
//hasil kartesius
System.out.println("====HASIL KASRTESIUS====" );
for(int i = 0 ; i <= anggotaA - 1 ; i++)
{
for( int w = 0 ; w <= anggotaB - 1 ; w++)
{
System.out.print("{" + a[i] + "," + b[w] + "}");
}
}
System.out.println("\n");
}
}
public class kartesius
{
public static void main ( String [] args)
{
Scanner input = new Scanner(System.in);
int[] a = new int [10];
int[] b = new int [10];
int anggotaA;
int anggotaB;
//masukkan banyaknya anggota a
do
{
System.out.print("Masukkan Banyaknya Himpunan A ( x<10 ) : ");
anggotaA = input.nextInt();
if(anggotaA > 10)
System.out.println("\n nilai harus \"x < 10\"\n");
}
while (anggotaA > 10);
//masukkan banyaknya anggota b
do
{
System.out.print("Masukkan Banyaknya Himpunan B ( y<10 ) : ");
anggotaB = input.nextInt();
if(anggotaB > 10)
System.out.println("\n nilai harus \"y < 10\"\n");
}
while (anggotaB > 10);
//masukkan elemen a
System.out.println("\nMasukkan Elemen Anggota A");
for(int i = 0 ; i <= anggotaA - 1 ; i++)
{
int z= i + 1;
System.out.print("\nElemen ke-["+z+"] : ");
a[i] = input.nextInt();
}
System.out.println("\n");
//masukkan elemen b
System.out.println("\nMAsukkan Anggota B");
for( int w = 0 ; w <= anggotaB - 1 ; w++)
{
int L = w + 1;
System.out.print("\nElemen ke-["+L+"] : ");
b[w] = input.nextInt();
}
System.out.println("\n");
//hasil kartesius
System.out.println("====HASIL KASRTESIUS====" );
for(int i = 0 ; i <= anggotaA - 1 ; i++)
{
for( int w = 0 ; w <= anggotaB - 1 ; w++)
{
System.out.print("{" + a[i] + "," + b[w] + "}");
}
}
System.out.println("\n");
}
}
Langganan:
Postingan (Atom)