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");
}
}
ni blog sepi amatt.... saya koment dech cil... biar seneng..
BalasHapus