Hi, I have a question regarding arrays in Java.
I want a user to
- decide how many numbers he want to type in and store in the array.
- Let the user type in the numbers.
- Show the numbers from the array backwards.
This is how my code looks like now. What am I doing wrong? Can anyone point me in the right direction?
import java.util.Scanner;
public class steg4egenlabb2 {
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int tal = 0;
System.out.print("Enter the amount of numbers you want to store in the array : ");
tal = keyboard.nextInt();
System.out.println("Enter " + tal + " numbers:");
int[] antal = new int[tal];
antal[0] = keyboard.nextInt();
System.out.println("The numbers written backwards:");
System.out.println(antal[0]);
}
}
This is how it currently shows with that code
Enter the amount of numbers you want to store in the array : 5
Enter 5 numbers:
1 2 3 4 5
The numbers written backwards:
1
Thanks