Welcome to Westonci.ca, the place where your questions are answered by a community of knowledgeable contributors. Experience the ease of finding precise answers to your questions from a knowledgeable community of experts. Discover in-depth answers to your questions from a wide network of professionals on our user-friendly Q&A platform.
Sagot :
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:\nNumber of digits in array: "+arrsize);
System.out.print("Digits in array: ");
for (int kount = 0; kount < arrsize; kount++) {
System.out.print(myarr[kount]+" "); }
}
}
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:\nNumber 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]+" "); }
Thank you for choosing our platform. We're dedicated to providing the best answers for all your questions. Visit us again. Thank you for your visit. We're dedicated to helping you find the information you need, whenever you need it. Find reliable answers at Westonci.ca. Visit us again for the latest updates and expert advice.