1
The objective is the following: read 10 values of a given vector, after that, create another vector, which has the same values of the first vector, but in inverted order, for example, the first value of the 1st vector is the tenth of the 2nd vector, the second value of the 1st vector is the penultimate of the 2nd vector, and so on. I tried to do but the second vector always has the value of 0. I know I have to use a for
for this, but I do not know if I used in the right way.
public static void main(String[] args) {
int [] firstArray = new int [10];
int [] secondArray = new int [10];
for (int i = 0; i < firstArray.length; i++) {
firstArray[i] =(int)Math.round(Math.random()*50); //Gerando valores aleatórios
}
//Passando valores
for (int i = 9; i <= 0; i--) {
for (int j = 0; j < secondArray.length; j++) {
secondArray[j] = firstArray[i];
break;
}
}
//Apresentar valores
System.out.println("\nPrimeiro Array:");
for (int i = 0; i < firstArray.length; i++) {
System.out.print(firstArray[i]+"; ");
}
System.out.println("\nSegundo Array:");
for (int i = 0; i < secondArray.length; i++) {
System.out.print(secondArray[i]+"; ");
}
System.out.println("");
}
This doesn’t make any sense at all. Enter the rest of the code.
– Maniero
@bigown I made some changes, see if you can help me :)
– Daniel Santos
Wouldn’t it be better to put the code you’re doing instead of posting loose snippets?
– Maniero
@I put Bigown, but I guess it hasn’t changed much ...
– Daniel Santos