Difference between revisions of "Creating an Array"
Line 6: | Line 6: | ||
|SideSectionTitle = Introducing Array | |SideSectionTitle = Introducing Array | ||
|SideSection= | |SideSection= | ||
− | [[Image:Wiki_array01.jpg|center]] | + | [[Image:Wiki_array01.jpg|center]]<BR> |
|Solution=First create the skeleton structure of your program | |Solution=First create the skeleton structure of your program |
Revision as of 15:27, 6 April 2010
Back to the Program-A-Day homepage
ProblemThere are ten students with ten grades. Instead of storing every single grade in a single variable it is easier to store this information in an array. Given that the grades are 56%, 34%, 75%, 89%, 78%, 87%, 71%, 67%, 98%, 85%, store the grades in an integer array as percents and convert them to decimals and store them in a double array. |
Introducing Array | |
---|---|---|
SolutionFirst create the skeleton structure of your program public class CreatingArray{ public static void main(){ } } Next, the two arrays to be used are integer and double, so we need to create the variables that will store these arrays. int[] intArray; double[] decimalArray; These will go inside the main program. Now a new array must be created, this is done with the new keyword. intArray = new int[10]; decimalArray = new double[10]; The 10 specifies the size of the array that you want to create. Now we will need to store the values inside | ||
Code |