answersLogoWhite

0


Best Answer

use a loop(for or while) to get the input from the user then store each in the array using the Scanner class

like this

import java.util.Scanner;//before class declaration

int[] Array = new int[10]; //just an example gets 10 ints from user

Scanner input = new Scanner(System.in);

then something like this

for(int i = 0; i < 10;i++)

{

System.out.println("enter number:");

Array[i]= input.nextInt();

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you store a number of integers entered by the user in an array with java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are the main features of arrays. How are arrays used and created?

AnswerWhat is an array: In programming languages, an array is a way of storing several items (such as integers). These items must have the same type (only integers, only strings, ...) because an array can't store different items. Every item in an array has a number so the programmer can get the item by using that number. This number is called the index. In some programming languages, the first item has index 0, the second item has index 1 and so on. But in some languages, the first item has index 1 (and then 2, 3, ...).


How do you write a program for counting and displaying occurrence of a number in an array?

Your first step is accepting input, which is done using the scanf() function:scanf("%d", &number);This means that you want scanf() to accept input, convert the input to a number, and store it in the memory at the address of number.Use a for() loop, counting from 0 to 9, and an array of integers to hold the numbers. Then simply scanf("%d", &intarray[counter]);The next step is a little tricky, but not very if you plan it out in advance.Each integer can contain 256, 65,536 or 4,294,967,296 different numbers. Creating an array to hold the count of each of those numbers is a waste of RAM.Instead, you'll want an "associative" array as follows:int numcount[MAXNUM][2];MAXNUM is 10, or the number of integers in the array you're checking. The second dimension, 2, consists of the number and its count.Obviously, you'll want a way to keep track of how many integers you've stored in numcount. An int called numcountnuminitialized to 0 would be the fastest way.Use a for() loop to iterate through the integers. If the integer does not exist in numcount, then set numcount[numcountnum][0] to the integer, set numcount[numcountnum][1] to 1, and increment numcountnum. Otherwise, if the integer exists, increase numcount[the integer index][1].Once the for() loop is finished, display the results. The only thing you have left to figure out is the function that searches the numcount array for an integer, and returns its index (or -1 if it's not found).


How do you initialize an array variable in java program?

An array in java is a collection of items stored into a single unit. The array has some number of slots (elements), each slot in the array can hold an object or a primitive value. Arrays in java are objects that can be treated just like other objects in the languageArrays can contain any type of element value , but we can't store different types in a single array. We can have an array of integers or an array of strings or an array of arrays.To create an array in java ,use three steps1. Declare a variable to hold the array2. Create a new array object and assign it to the array variable3. Store things in that array


What is string array?

A string array is an array whose contents are strings.An array is when you use a single variable names to store different data items. The data items are distinguished by a number (sometimes by more than one).A string is a data type used to store texts. It may contain letters, digits, or other symbols.A string array is an array whose contents are strings.An array is when you use a single variable names to store different data items. The data items are distinguished by a number (sometimes by more than one).A string is a data type used to store texts. It may contain letters, digits, or other symbols.A string array is an array whose contents are strings.An array is when you use a single variable names to store different data items. The data items are distinguished by a number (sometimes by more than one).A string is a data type used to store texts. It may contain letters, digits, or other symbols.A string array is an array whose contents are strings.An array is when you use a single variable names to store different data items. The data items are distinguished by a number (sometimes by more than one).A string is a data type used to store texts. It may contain letters, digits, or other symbols.


How can you dicribe array?

An array is when you store several data items with a single name. You only use a number to distinguish the individual items. Or two or more numbers, if you use a multidimensional array.An array is when you store several data items with a single name. You only use a number to distinguish the individual items. Or two or more numbers, if you use a multidimensional array.An array is when you store several data items with a single name. You only use a number to distinguish the individual items. Or two or more numbers, if you use a multidimensional array.An array is when you store several data items with a single name. You only use a number to distinguish the individual items. Or two or more numbers, if you use a multidimensional array.


What is an array in java perspective?

In java,an array is a wrapper class.An array is an object and it gets room in heap.Array can store a collection of data's of same datatype.It can be used to store integers,strings even objects..its collections of data's.Wheather the array stores primitive data,s or objects in it an array s always an object. int numbers[] = new int[10]; this array is of size 10 which can hold 10 int values.This array numbers stores primitive data type but the array number is an object Each item in an array is called an element, and each element is accessed by its numerical index. As shown in the above illustration, numbering begins with 0. The 9th element, for example, would therefore be accessed at index 8.


How do arrays differ from single memory position variables?

A single memory position variable can store only one value of its type. An array can store n number of values, where n is the size of the array.


What is arry as in java?

An array is a contiguous block of memory in which to store data. For instance, an array of integers is essentially a chunk of memory with integers stored one after another. // Use [] to define an array of the given type. int[] intArray; // Instantiate intArray with enough space to hold 100 ints. intArray = new int[100]; // Store some data... int[0] = 100; int[1] = 99; int[2] = 98; ... int[99] = 1; // Retrieve some data... for(int i = 0; i &lt; intArray.length; ++i) { System.out.println(intArray[i]); }


How do you write a c plus plus program that randomly generates 100 integer values and store them in an array?

// generate 100 integers in the closed range [1:9] and store in an array. std::default_random_engine generator ((unsigned) time (0)); std::uniform_int_distribution&lt;int&gt; distribution (1,9); std::array&lt;int, 100&gt; a; for (size_t loop=0; loop!=100; ++loop) a[loop] = distribution (generator);


What are the similarities between rational numbers and fractions?

All integers belong to the set {..., -2, -1, 0, 1, 2, ...}. The absolute value of any integer results in a whole number {0, 1, 2, ...}. Adding and subtracting integers always results in an integer. Multiplying integers always results in an integer. Dividing integers can sometimes not result in an integer.


How can you store Class properties in Array in c?

Yes, you can create array that will store class properties. But all of them have to be of the same type.


Why object array called universal array?

Object array is called universal array because it can store multiple variables of the same type