LISTING PROGRAM
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(",");
}
}
}
}
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(",");
}
}
}
}
LOGIKA PROGRAM
nama=["mohamad","ardi","ansyah"] sebuah nama berisikan mohamad,ardi,ansyah ini bias diartikan juga sebagai sebuah inputan,tetapi inputan ini sudah terdapat didalam program sehingga akan langsung keluar output tanpa meminta inputan
npm=["53409605","50409023","50409014"] sebuah npm berisikan 53409605,50409023,50409014 dalam program ini inputan sudah ada dalam program.
nilai=[] artinya parameter nilai siap dimasukkan suatu nilai atau inputan
print "Masukkan nilai mahasiswa 1 : ","\n" akan mencetak tulisan masukkan nilai mahasiswa 1 :
nilai[0]=gets.to_i artinya parameter nilai berisikan nilai 0 dan tipe data nilai tersebuat berubah menjadi integer
print"Masukkan nilai mahasiswa 2 : ","\n" a akan mencetak tulisan masukkan nilai mahasiswa 2 :
nilai[1]=gets.to_i artinya parameter nilai berisikan nilai 1 dan tipe data nilai tersebuat berubah menjadi integer
print"Masukkan nilai mahasiswa 3 : ","\n" akan mencetak tulisan masukkan nilai mahasiswa 3 :
nilai[2]=gets.to_i artinya parameter nilai berisikan nilai 2 dan tipe data nilai tersebuat berubah menjadi integer
print"Nama mahasiswa 1 : ",nama[0],"\n"
print"NPM mahasiswa 2 : ",npm[0],"\n"
print"Nilai mahasiswa 3 : ",nilai[0],"\n"
maksudnya akan mencetak tulisan dalam petik, dan akan keluar nialai parameter berdasarkan program diatas dimulai dari 0,jadi akan menhasilakan output berdasarkan inputan didalam program
Post a Comment