Answer:
In Java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int arrsize;
System.out.print("Please enter the number of digits to be stored: ");
arrsize = input.nextInt();
int[] myarr = new int[arrsize];
for (int kount = 0; kount < arrsize; kount++) {
System.out.print("Enter integer: ");
myarr[kount] = input.nextInt(); }
System.out.println("The contents of your array:\\Number of digits in array: "+arrsize);
System.out.print("Digits in array: ");
for (int kount = 0; kount < arrsize; kount++) {
System.out.print(myarr[kount]+" "); }
}
}
Step-by-step explanation:
This declares the length of the array
int arrsize;
This prompts the user for the array length
System.out.print("Please enter the number of digits to be stored: ");
This gets the input for array length
arrsize = input.nextInt();
This declares the array
int[] myarr = new int[arrsize];
The following iteration gets input for the array elements
for (int kount = 0; kount < arrsize; kount++) {
System.out.print("Enter integer: ");
myarr[kount] = input.nextInt(); }
This prints the header and the number of digits
System.out.println("The contents of your array:\\Number of digits in array: "+arrsize);
System.out.print("Digits in array: ");
The following iteration prints the array elements
for (int kount = 0; kount < arrsize; kount++) {
System.out.print(myarr[kount]+" "); }