Selasa, 25 Mei 2010

program matif vector

Listing Program

import javax.swing.*;

class vektor

{

public static void main(String[] args) throws Exception

{

int i,j,k,temp;

int n = Integer.parseInt(JOptionPane.showInputDialog("Masukkan jumlah elemen vektor :"));

int[] jum = new int[10];

int[] v1 = new int[10];

int[] v2 = new int[10];

int[] skal = new int[10];

for (i=0;i

{

int m = Integer.parseInt(JOptionPane.showInputDialog("Vektor A elemen {"+(i+1)+"}"));

v1 [i] = m;

}

for (i=0;i

{

for (i=0;i

{

int m = Integer.parseInt(JOptionPane.showInputDialog("Vektor B elemen {"+(i+1)+"}"));

v2 [i] = m;

}

}

for (i=0;i

{

System.out.print("Vektor A = [");

for (i=0;i

{

System.out.print(v1 [i]);

if(i!=n-1)

{

System.out.print(",");

}

}

System.out.print("]");

System.out.print("\n");

}

for (i=0;i

{

System.out.print("Vektor B = [");

for (i=0;i

{

System.out.print(v2 [i]);

if(i!=n-1)

{

System.out.print(",");

}

}

System.out.print("]");

System.out.print("\n");

}

System.out.print("Penjumlahan vektor = [");

for(i = 0;i

{

jum[i] = v1[i] + v2[i] ;

System.out.print(jum[i]);

if(i!=n-1)

{

System.out.print(",");

}

}

System.out.print("]");

System.out.print("\n");

System.out.print("Pengurangan vektor = [");

for(i = 0;i

{

jum[i] = v1[i] - v2[i] ;

System.out.print(jum[i]);

if(i!=n-1)

{

System.out.print(",");

}

}

System.out.print("]");

System.out.print("\n");

System.out.print("Perkalian vektor = [");

for(i = 0;i

{

jum[i] = v1[i] * v2[i] ;

System.out.print(jum[i]);

if(i!=n-1)

{

System.out.print(",");

}

}

System.out.print("]");

System.out.print("\n\n");

System.out.print("Perkalian Vektor dengan skalar");

System.out.print("\n");

int a = Integer.parseInt(JOptionPane.showInputDialog("Masukkan nilai skalar : "));

System.out.print("Nilai skalar = "+a);

System.out.print("\n");

System.out.print("Vektor A = [");

for(i = 0;i

{

skal[i] = a * v1 [i];

System.out.print(skal[i]);

if(i!=n-1)

{

System.out.print(",");

}

}

System.out.print("]");

System.out.print("\n");

System.out.print("Vektor B = [");

for(i = 0;i

{

skal[i] = a * v2 [i];

System.out.print(skal[i]);

if(i!=n-1)

{

System.out.print(",");

}

}

System.out.print("]");

System.out.print("\n");

}

}

Tidak ada komentar:

Posting Komentar