import java.io.*;
class vektor
{
public static void main (String[]vektor) throws IOException
{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
int[]jum = new int[100];
int[]v1 = new int[100];
int[]v2 = new int[100];
int i;
int n;
int m;
System.out.println();
System.out.print("Masukkan Jumlah Elemen Vektor= ");
n = Integer.parseInt(input.readLine());
System.out.println();
System.out.println("Vektor 1");
for (i=0;i<n;i++)
{
System.out.print("Elemen[1,"+i+"]= ");
v1[i] = Integer.parseInt(input.readLine());
}
System.out.println();
System.out.println("Vektor 2");
for (i=0;i<n;i++)
{
System.out.print("Elemen[1,"+i+"]= ");
v2[i] = Integer.parseInt(input.readLine());
}
System.out.print("\nPenjumlahan Vektor: [");
for (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 (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 (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.println("");
System.out.print("\nMasukkan Angka Skalar= ");
m = Integer.parseInt(input.readLine());
System.out.print("\nPerkalian Vektor Skalar 1: [");
for (i=0;i<n;i++)
{
jum[i]=m*v1[i];
System.out.print(jum[i]);
if (i!=n-1)
{
System.out.print(",");
}
}
System.out.print("]");
System.out.print("\nPerkalian Vektor Skalar 2: [");
for (i=0;i<n;i++)
{
jum[i]=m*v2[i];
System.out.print(jum[i]);
if (i!=n-1)
{
System.out.print(",");
}
}
System.out.print("]");
System.out.println("");
}
}
class vektor
{
public static void main (String[]vektor) throws IOException
{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
int[]jum = new int[100];
int[]v1 = new int[100];
int[]v2 = new int[100];
int i;
int n;
int m;
System.out.println();
System.out.print("Masukkan Jumlah Elemen Vektor= ");
n = Integer.parseInt(input.readLine());
System.out.println();
System.out.println("Vektor 1");
for (i=0;i<n;i++)
{
System.out.print("Elemen[1,"+i+"]= ");
v1[i] = Integer.parseInt(input.readLine());
}
System.out.println();
System.out.println("Vektor 2");
for (i=0;i<n;i++)
{
System.out.print("Elemen[1,"+i+"]= ");
v2[i] = Integer.parseInt(input.readLine());
}
System.out.print("\nPenjumlahan Vektor: [");
for (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 (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 (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.println("");
System.out.print("\nMasukkan Angka Skalar= ");
m = Integer.parseInt(input.readLine());
System.out.print("\nPerkalian Vektor Skalar 1: [");
for (i=0;i<n;i++)
{
jum[i]=m*v1[i];
System.out.print(jum[i]);
if (i!=n-1)
{
System.out.print(",");
}
}
System.out.print("]");
System.out.print("\nPerkalian Vektor Skalar 2: [");
for (i=0;i<n;i++)
{
jum[i]=m*v2[i];
System.out.print(jum[i]);
if (i!=n-1)
{
System.out.print(",");
}
}
System.out.print("]");
System.out.println("");
}
}
Output Program
Yang bingung komen..
ReplyDelete