The code below works as it should, in case anyone wants to use it, I thank all those who commented
Giving linear algebra are teaching me operations with vectors and to simplify my life I wanted to make a code for this, I am not very proficient with the code yet. Surfing the Internet I came across this for the java language.
import java.util.Scanner;
public class OperacionVectores{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
//Variables k seran el tamaño de los vectores
int v1,v2,v3;
System.out.print("Ingrese el tamaño del vector 1: ");
v1=sc.nextInt();
//creamos el primer vector con el tamaño de v1
double vec1[]=new double[v1];
//recorremos el vector v1 para llenarlo
for(int i1=0;i1<vec1.length;i1++){
System.out.print("\n ingrese el numero de la posicion "+i1+":");
vec1[i1]=sc.nextDouble();
}
System.out.print("\n Ingrese el tamaño del vector 2: ");
v2=sc.nextInt();
//Creamos el primer vector con el tamaño de v1
double vec2[]=new double[v2];
//recorremos el vector v2 para llenarlo
for(int i2=0; i2<vec2.length;i2++){
System.out.print("ingrese el numero de la posicion "+i2+":");
vec2[i2]=sc.nextDouble();
}
/*Determinamos cual de los dos vectores es mas grande,
para k el vector 3 tenga el tamaño del mas grande*/
v3=v1;
if (v2 > v1)
v3=v2;
//Declaramos el vector 3
double vec3[]=new double[v3];
//recorremos el vector 3 para hacer la suma
for(int i3=0;i3<vec3.length;i3++){
double valv1=0.0;
if (vec1.length > i3){
valv1 = vec1[i3];
}
double valv2=0.0;
if(vec2.length > i3){
valv2=vec2[i3];
}
/*Hacemos la suma de las posiciones de los vectores 1 y 2 en las
posiciones del vector 3*/
vec3[i3]=valv1*valv2;
System.out.println("\nLa Suma de la Posicion"+" "+i3+" "+ "es:"+vec3[i3]);
}
}
}
First the code is not mine, the only thing that I have changed, from my point of view, is the type of variable from int to double, because the vectors are decimals.
If I leave all the variables as integer the code works great, but when I do the change from int to double it tells me this
Exception in thread "main" java.lang.NullPointerException at OperacionVectores.main (OperationVectores.java:40)
I think the problem is after the line that says v3 = v1 thank you very much for your help