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.

Create an array of that size and then prompt the user for numbers to fill each position in the array. When all of the positions are filled, display the contents of the array to the user. Below is a sample transcript of what your program should do. Text in bold is expected input from the user rather than output from the program.Please enter the number of digits to be stored: 5Enter integer 0: -1Enter integer 1: 10Enter integer 2: 15Enter integer 3: -6Enter integer 4: 3The contents of your array:Number of digits in array: 5Digits in array: -1 10 15 -6 3

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.