0
I would like to perform a multiplication between two vectors, each with its corresponding, as I can illustrate below:
i = [a1, a2, a3, ...]
j = [b1, b2, b3, ...]
I could end up with a third vector, like this one:
i x j = [a1*b1, a2*b2, a3*b3, ...]
I explain to you why this, because at the end of this operation, I would like to add all the components of this vector.
The application of the code will be for the user to provide sizes (millimeters) in one vector, and quantity (pieces) in another vector, so need there to be multiplication to obtain the total linear quantity of the product and at the end the linear quantity of everything that was provided.
The code I thought goes below:
int n = 5;
int comprimento_vetor[] = new int[n];
int i = 0;
int s = 5;
int qtd_vetor[] = new int[s];
int j = 0;
while (i <= 4) {
System.out.printf("Inserir o comprimento da telha T%d: ", (i + 1));
comprimento_vetor[i] = sc.nextInt();
if (i > 4) {
break;
} else {
System.out.printf("Gostaria de inserir nova telha? S / N: ");
String confirmacao_telha = sc.next();
char letra = confirmacao_telha.charAt(0);
if (letra == 'S') {
i++;
} else {
System.out.printf(
"--------%n"
+ "Comprimentos:%n"
+ "T1: %d%n"
+ "T2: %d%n"
+ "T3: %d%n"
+ "T4: %d%n"
+ "T5: %d%n"
+ "--------%n",
comprimento_vetor[0], comprimento_vetor[1],
comprimento_vetor[2], comprimento_vetor[3],
comprimento_vetor[4]);
while (j <= 4) {
System.out.printf("Inserir a quantidade da telha T%d: ", (p + 1));
qtd_vetor[p] = sc.nextInt();
System.out.printf("Gostaria de inserir nova quantidade? S / N: ");
String confirmacao_qtd = sc.next();
char letra1 = confirmacao_qtd.charAt(0);
if (letra1 == 'S') {
j++;
} else {
System.out.printf(
"--------%n"
+ "Quantidades:%n"
+ "T1: %d%n"
+ "T2: %d%n"
+ "T3: %d%n"
+ "T4: %d%n"
+ "T5: %d%n"
+ "--------%n",
qtd_vetor[0], qtd_vetor[1],
qtd_vetor[2], qtd_vetor[3],
qtd_vetor[4]);
break;
}
}
And what is the doubt / the problem?
– Ronaldo Araújo Alves
I would like to know how to implement the multiplication code of the positions of the vectors I commented at the beginning of the text, I tried to contextualize too much I believe what I was implementing.
– Sander dos Santos Zuchinalli