Want this question answered?
In Java, assuming you already created an array of int's, called myArray:int max = myArray[0];int sum = 0;for (int i = 0; i < myArray.length; i++){sum += myArray[i];if (myArray[i] > max)sum = myArray[i]}
In Java:int[] myArray;// or: int myArray[]followed by:myArray = new int[16];Instead of int, you can use any other data type, including a class.
Use the array suffix operator ([]), or use a pointer offset from the start of the array, such that an offset of 1 is equivalent to the size of an array element (all elements in an array must be of equal size). The latter method is what actually goes on behind the scenes when using the array suffix operator, but the former is generally easier to use.
An array stores several values - for example, several numbers - using a single variable name. The programmer can access the individual values with a subscript, for example, myArray[0], myArray[5]. The subscript can also be a variable, for example, myArray[i], making it easy to write a loop that processes all the elements of an array, or some of them, one after another.
An example might help int myarray [] = {2,0,1,3,1,1,2,9};
For instance, you have array of type int with a name myArray, and you do not know size of the array. You can use following statement to get it:int arraySize = myArray/myArray[0];arraySize gives you number of elements in myArray.
Assuming the numbers are integers, and they are stored in an array called myArray. The following has not been tested, but gives the general idea: int max; max = myArray[0]; for (int i = 1; i < myArray.length(); i++) } if (myArray[i] > max) max = myArray[i]; System.out.println(max); }Assuming the numbers are integers, and they are stored in an array called myArray. The following has not been tested, but gives the general idea: int max; max = myArray[0]; for (int i = 1; i < myArray.length(); i++) } if (myArray[i] > max) max = myArray[i]; System.out.println(max); }Assuming the numbers are integers, and they are stored in an array called myArray. The following has not been tested, but gives the general idea: int max; max = myArray[0]; for (int i = 1; i < myArray.length(); i++) } if (myArray[i] > max) max = myArray[i]; System.out.println(max); }Assuming the numbers are integers, and they are stored in an array called myArray. The following has not been tested, but gives the general idea: int max; max = myArray[0]; for (int i = 1; i < myArray.length(); i++) } if (myArray[i] > max) max = myArray[i]; System.out.println(max); }
In Java, assuming you already created an array of int's, called myArray:int max = myArray[0];int sum = 0;for (int i = 0; i < myArray.length; i++){sum += myArray[i];if (myArray[i] > max)sum = myArray[i]}
There are two types of arrays, associative arrays, and indexed arrays. Indexed arrays are where you access the items in order, for example $myArray[0] would be the first item in the array, $myArray[1] would be the second item, and so on. You can create an indexed array like this: $myArray = array("item1","item2","item3"); echo $myArray[0]; //item1 echo $myArray[2]; //item3 You can also set your own indexes: $myArray = array(0=>"item1", 1=>"item2", 5=>"number 5"); echo $myArray[0]; //item1 echo $myArray[2]; //null or doesnt exist, i cant remember You can also add items after using the square-brackets. If you include a number, that index is set, otherwise it just adds it to the end of the array. $myArray[9] = "set index 9"; $myArray[] = "add to the end of the array"; Associative arrays use strings instead of numbers. $colors = array("cat"=>"brown", "dog"=>"yellow", "fish"=>"purple"); echo $colors["cat"]; //brown echo $colors["fish"]; //purple And you can add more with the square-brackets again. $colors["camel"] = "green"; To loop through both types of arrays you can use a foreach loop, or to loop through indexed arrays you can get the length into a variable and a do normal for loop.
name of array point to the first element of array. actually when we use int myarray[10]; compiler make space for 10 integer in sequence (if 2 byte for each int then 20 byte for 10). and name of the array in this case myarray point to the first element of that sequence. When we say myarray[n] (0 <= n < 10 in this case), then this is treated as, content of address, myarray + (n*byte_per_integer).
In Java:int[] myArray;// or: int myArray[]followed by:myArray = new int[16];Instead of int, you can use any other data type, including a class.
You have array of type int with a name myArray, and you do not know size of the array.
Use the array suffix operator ([]), or use a pointer offset from the start of the array, such that an offset of 1 is equivalent to the size of an array element (all elements in an array must be of equal size). The latter method is what actually goes on behind the scenes when using the array suffix operator, but the former is generally easier to use.
struct Foobar myarray [32]; or struct { int foo; double bar; } myarray [32];
An array stores several values - for example, several numbers - using a single variable name. The programmer can access the individual values with a subscript, for example, myArray[0], myArray[5]. The subscript can also be a variable, for example, myArray[i], making it easy to write a loop that processes all the elements of an array, or some of them, one after another.
Yes, you can but the array must be char-type. ... int arraySize = 3;char myArray[arraySize]; ... for (intarrayIndex = 0; arrayIndex < arraySize; arrayInsex++) { cin >> myArray[arrayIndex]; //It will write three character (keys which you pressed) in myArray} ...
int myArray[] = {1,2,3,4,5};