Preview

Example of Array for It Students

Better Essays
Open Document
Open Document
1094 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Example of Array for It Students
Arrays

An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed. You've seen an example of arrays already, in the main method of the "Hello World!" application. This section discusses arrays in greater detail.

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.

The following program, ArrayDemo, creates an array of integers, puts some values in it, and prints each value to standard output.

class ArrayDemo { public static void main(String[] args) { // declares an array of integers int[] anArray;

// allocates memory for 10 integers anArray = new int[10]; // initialize first element anArray[0] = 100; // initialize second element anArray[1] = 200; // etc. anArray[2] = 300; anArray[3] = 400; anArray[4] = 500; anArray[5] = 600; anArray[6] = 700; anArray[7] = 800; anArray[8] = 900; anArray[9] = 1000;

System.out.println("Element at index 0: " + anArray[0]); System.out.println("Element at index 1: " + anArray[1]); System.out.println("Element at index 2: " + anArray[2]); System.out.println("Element at index 3: " + anArray[3]); System.out.println("Element at index 4: " + anArray[4]); System.out.println("Element at index 5: " + anArray[5]); System.out.println("Element at index 6: " + anArray[6]); System.out.println("Element at

You May Also Find These Documents Helpful

  • Good Essays

    Nt1420 Unit 6

    • 1145 Words
    • 5 Pages

    Question 6 A hash table is a data structure that uses an array as its internal storage container. Items are added to the array based on the integer generated by a hash function. A hash function produces an integer based on some properties of the object. In Java hash functions are encapsulated via the hashcode method in the Object class and that many classes override.…

    • 1145 Words
    • 5 Pages
    Good Essays
  • Powerful Essays

    System.out.println("i = " + i + " f = " + f + " d = " + d);…

    • 2338 Words
    • 10 Pages
    Powerful Essays
  • Good Essays

    Arrays store items that have the same type of data type like a group of employees’ names and social security numbers for a team of 2000 personal. Pointer is a variable that greatly extends the power and flexibility of a program, each memory location that is used to store data value has an address. The address provides the means for a PC hardware to reference a particular data item.…

    • 485 Words
    • 2 Pages
    Good Essays
  • Good Essays

    I = { . . ., -4, -3, -2, -1, 0, 1, 2, 3, 4, . . .}.…

    • 1254 Words
    • 6 Pages
    Good Essays
  • Good Essays

    Array Structure Paper

    • 833 Words
    • 4 Pages

    “An array is a collective name given to a group of similar quantities. These similar quantities could be percentage marks of 100 students, number of chairs in home, or salaries of 300 employees or ages of 25 students. Thus an array is a collection of similar elements. These similar elements could be all integers or all characters, and so on” (Thompson, 2007). Building an array can be confusing for the Bug Blasters can be very confusing for a programmer who does not fully understand how they work.…

    • 833 Words
    • 4 Pages
    Good Essays
  • Good Essays

    Chapter 8 Quiz

    • 469 Words
    • 2 Pages

    2. What is the term used for the number inside the bracket that specifies the number of values that an array can hold? (Points : 7)…

    • 469 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    E4.6: The label array_x is the starting address of an array of 100 8bit elements.…

    • 900 Words
    • 4 Pages
    Satisfactory Essays
  • Good Essays

    Programming Logic

    • 1499 Words
    • 6 Pages

    2. Design the logic for a program that outputs every number from 1 through 10.…

    • 1499 Words
    • 6 Pages
    Good Essays
  • Good Essays

    • You have approximately 25 hours in which to complete this scenario. • Before starting work on the problem, read the whole of this Candidate Booklet thoroughly. You can…

    • 1453 Words
    • 6 Pages
    Good Essays
  • Good Essays

    Sheet Java Study Guide

    • 576 Words
    • 3 Pages

    1. Write a program to compute the area and circumference of a rectangle 3 inche wide by 5 inches long.…

    • 576 Words
    • 3 Pages
    Good Essays
  • Good Essays

    array - noun an arrangement of aerials spaced to give desired directional characteristics; especially fine or decorative clothing; an impressive display; an orderly arrangement; verb align oneself with a group or a way of thinking; lay out orderly or logically in a line or as if in a line…

    • 845 Words
    • 4 Pages
    Good Essays
  • Good Essays

    Programming Homework

    • 366 Words
    • 2 Pages

    The output required from this program will be a multiplication table going from 1 x 1 all the way to 10 x 10 with a new line after every 10 products.…

    • 366 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    It 218 Week 4 Checkpoint

    • 290 Words
    • 2 Pages

    An array is a variable that holds more than more than one value, and an array can be combined with multiple variables for a more complex structure. An array is declared much similar with any other variable. The only difference is the number of elements is shown in brackets. An example of an array will be look much like these three: calories [ min ], 30 [ 7 ], and feet [ 12 ]. Each one of these arrays can be used as long as it is appropriate for the program.…

    • 290 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Assignment 3 CS 113

    • 804 Words
    • 5 Pages

    For each number x input by the user the program displays (prints) “x is in the list” or…

    • 804 Words
    • 5 Pages
    Good Essays
  • Powerful Essays

    A smart phone is definitely a mini computer that will do the same as a larger computer, as well as work as a phone and a camera. The smart phone processes information through aps to help a user to work, or just to be entertained, as well as surf the internet.…

    • 1161 Words
    • 5 Pages
    Powerful Essays