Advertisement
ipwxy

Array Variables

Jun 28th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. /**
  2. Arrays allow us to store multiple values in a single variable.
  3.  
  4. They are distinguished from other variables using brackets: []
  5. */
  6.  
  7.     int[] numbers;
  8.    
  9. /**
  10. Array values consist of the keyword "new", followed by the type, followed by brackets with a number inside.
  11. */
  12.  
  13.     numbers = new int[5];
  14.  
  15. /**
  16. The number in the brackets determine how many indexes this array has.
  17.  
  18. To access an index, you use brackets to determine which index you want to access.
  19. */
  20.  
  21.     numbers[0] = 10;
  22.  
  23. /**
  24. Arrays are indexed starting at 0.
  25.  
  26. This means you can access indexes 0 to 4 from numbers, for a total of 5 values.
  27. */
  28.  
  29.     numbers[0] = 10;
  30.     numbers[1] = 10;
  31.     numbers[2] = 10;
  32.     numbers[3] = 10;
  33.     numbers[4] = 10;
  34.  
  35. /**
  36. Arrays have a special property: length
  37. It determines how many indexes there are.
  38. */
  39.  
  40.     System.out.println(numbers.length); // prints 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement