I need help making an array that prints out multiples of a given number. The output looks like this:
Enter a positive integer: 8
Test array: 1 1 2 3 5 8 13
Counting up: 1 2 3 4 5 6 7 8
Counting down: 8 7 6 5 4 3 2 1
The first 8 multiples of 5: 5 10 15 20 25 30 35 40
The first 8 multiples of 10: 10 20 30 40 50 60 70 80
This is what I have so far in code:
//Creates an array that counts up to the user input
public static int[] countUp(int n){
int [] temp = new int[n];
for(int i=0; i<n; i++){
temp[i] = i+1;
}
return temp;
}
//Creates an array that counts down to the user input
public static int[] countDown(int n){
int [] temp = new int[n];
for(int i=0; i<temp.length; i++){
temp[i] = n--;
}
return temp;
}
//Creates an array that gets n amount of multiples of 5
public static int[] getMultiplesOfFive(int n){
int [] temp = new int[n];
for(int i=0; i<temp.length; i++){
temp[i] = n+5;
}
return temp;
}
//Creates an array that gets n amount of multiples of 10
public static int[] getMultiplesOfTen(int n){
int [] temp = new int[n];
for(int i=0; i<temp.length; i++){
temp[i] = n+10;
}
return temp;
}
}
However my output looks like this:
Enter a positive integer: 8
Test array: 1 1 2 3 5 8 13
Counting up: 1 2 3 4 5 6 7 8
Counting down: 8 7 6 5 4 3 2 1
The first 8 multiples of 5: 13 13 13 13 13 13 13 13
The first 8 multiples of 10: 18 18 18 18 18 18 18 18
Obviously the problem is in the last two arrays called getMultiplesofFive and getMultiplesofTen. I'm just not sure how to create a loop that gives me the correct output. Thank you so much!