Pages

Kamis, 19 Januari 2012

Java - Penjumlahan, Pengurangan dan Perkalian Vektor

Post kali ini bertemakan mengenai perhitungan vektor yang diaplikasikan menggunakan program Java. pada program ini kita dapat menghitung nilai vektor baik penjumlahan, pengurangan dan perkalian.
berikut listing codenya
import java.io.*;

class vektoor
{
            public static void main (String[] args) throws Exception
            {
                        BufferedReader Input = new BufferedReader( new InputStreamReader (System.in));
                       
                        int [] jum = new int [10];
                        int [] v1 = new int [10];
                        int [] v2 = new int [10];
                       
                        System.out.print("masukan jumlah elemen vektor =");
                        int n=Integer.parseInt(Input.readLine());
                        System.out.println("vektor 1");
                        for(int i=0;i<n;i++)
                        {
                                    System.out.print("elemen [1,"+i+"]=");
                                     v1[i]=Integer.parseInt(Input.readLine());
                        }
                        System.out.println("vektor 2");
                        for(int i=0;i<n;i++)
                        {
                                    System.out.print("elemen [1,"+i+"]=");
                                     v2[i]=Integer.parseInt(Input.readLine());
                        }
                        System.out.print("\npenjumlahan vektor:[");
                        for(int i=0;i<n;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("\npengurangan vektor:[");
                        for(int i=0;i<n;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("\nperkalian vektor:[");
                        for(int i=0;i<n;i++)
                        {
                                     jum[i]=v1[i]*v2[i];
                                    System.out.print(jum[i]);
                                    if(i!=n-1)
                                    {
                                                System.out.print(",");
                                    }
                                   
                        }
                        System.out.print("]");
            }
}

setelah semua syntak telah diketikkan dalam editor java, maka output yang dihasilkan adalah
demikian posting java kali ini semoga dapat membantu :D

1 komentar:

anak-jelex mengatakan...

kunjungan hangat.. kunjung balik ya. jangan lupa follownya.. :D

Posting Komentar