I filled an array with the numbers 1 to 10 using a for-loop
.
Now I need to fill a second array with the values of the first array, but upside down. So the second array has to be filled with 10 to 1.
I tried something but it fills the second array with just 1.
output is:
1
2
3
4
5
6
7
8
9
10
1
1
1
1
1
1
1
1
1
1
and it should be 1 2 3 4 5 6 7 8 9 10 10 9 8 7 6 5 4 3 2 1
package FillandTurn;
import java.util.Scanner;
/**
*
* @author Quinten
*/
public class FillandTurn {
/**
* @param args the command line arguments
*/
Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
// TODO code application logic here
FillandTurn fill = new FillandTurn();
fill.start();
}
public void start(){
FillandTurn turn = FillandTurn();
int[] array = turn.vullen();
int[] array2 = turn.draaien(array);
}
public int[] fill(){
int[] array = new int[10];
int j = 0;
for(int i = 0; i < array.length; i++ ){
j++;
array[i] = j;
}
for(int p = 0; p <= array.length-1; p++ ){
System.out.println(array[p]);
}
return array;
}
public int[] turn(int[] array){
int[] array2 = new int[10];
for(int x = 0; x < array2.length; x++){
for(int y = array.length-1; y >=0; y--){
array2[x] = array[y];
}
}
for(int p = 0; p <= array2.length-1; p++ ){
System.out.println(array2[p]);
}
return array2;
}
}
Any helps is appreciated!