class Exercicio6 {
public static void main
(String[] args
) { float somaV1 = 0, somaV2 = 0;
float[] vetor1 = {4.3f, 2.5f, 4.7f};
float[] vetor2 = {5.7f, 5.8f, 3.7f};
for(int i = 0; i < vetor1.length; i++){
somaV1 += vetor1[i];
somaV2 += vetor2[i];
}
for (int i = 0; i < vetor2.length; i++){
//somaV2 += vetor2[i];
}
System.
out.
print("Vetor 1 [" + vetor1
[0] + ", " + vetor1
[1]); System.
out.
println(", " + vetor1
[2] + "] Soma = " + somaV1
); System.
out.
print("Vetor 2 [" + vetor2
[0] + ", " + vetor2
[1]); System.
out.
println(", " + vetor2
[2] + "] Soma = " + somaV2
);
float[] vetor3 = new float[6];
if (somaV1 > somaV2) {
System.
arraycopy(vetor1,
0, vetor3,
0, vetor1.
length); System.
arraycopy(vetor2,
0, vetor3,
3, vetor2.
length); System.
out.
println("\nVetor 1 com maior soma, resultado final:\n"); System.
out.
print("Vetor 3 [" + vetor3
[0] + ", " + vetor3
[1] + ", " + vetor3
[2]); System.
out.
print(", " + vetor3
[3] + ", " + vetor3
[4] + ", " + vetor3
[5] + "]"); } else {
System.
arraycopy(vetor2,
0, vetor3,
0, vetor2.
length); System.
arraycopy(vetor1,
0, vetor3,
3, vetor1.
length); System.
out.
print("\nVetor 2 com maior soma, resultado final:\n"); System.
out.
print("Vetor 3 [" + vetor3
[0] + ", " + vetor3
[1] + ", " + vetor3
[2]); System.
out.
print(", " + vetor3
[3] + ", " + vetor3
[4] + ", " + vetor3
[5] + "]"); }
}
}
Y2xhc3MgRXhlcmNpY2lvNiB7CiAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgZmxvYXQgc29tYVYxID0gMCwgc29tYVYyID0gMDsKICAgIGZsb2F0W10gdmV0b3IxID0gezQuM2YsIDIuNWYsIDQuN2Z9OwogICAgZmxvYXRbXSB2ZXRvcjIgPSB7NS43ZiwgNS44ZiwgMy43Zn07CiAgIAogICAgZm9yKGludCBpID0gMDsga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