Jamiemcg

Yahoo! Answers - Printing Numbers from an Array

Oct 30th, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. /* Yahoo! Answers - Question Response
  2.  * Question URL: https://answers.yahoo.com/question/index?qid=20141030194030AAs7PKq
  3.  * Author: Jamie
  4.  * TechnicalCafe.com
  5.  * Source: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
  6.  **/
  7.  
  8. public class PrintArray{
  9.  
  10.     public static void main(String [] args){
  11.  
  12.         //create a new array of type "int" with five indices (0-4) to hold five integers
  13.         int[] intArray = new int[5];
  14.  
  15.         //manually add some values to the array (this can be done using a "for loop", as well)
  16.         intArray[0] = 1;
  17.         intArray[1] = 2;
  18.         intArray[2] = 3;
  19.         intArray[3] = 4;
  20.         intArray[4] = 5;
  21.  
  22.         //Now that we have added five integers to our array, we can print it using a "for loop", rather than
  23.         //having to write five separate "System.out.println()" statements
  24.         for(int i = 0; i <= 4; i++){
  25.            
  26.             //print out the value stored in the "ith" index of the "intArray" array
  27.             System.out.println(intArray[i]);
  28.  
  29.         }
  30.  
  31.     }
  32.  
  33. }
Add Comment
Please, Sign In to add comment