Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Yahoo! Answers - Question Response
- * Question URL: https://answers.yahoo.com/question/index?qid=20141030194030AAs7PKq
- * Author: Jamie
- * TechnicalCafe.com
- * Source: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
- **/
- public class PrintArray{
- public static void main(String [] args){
- //create a new array of type "int" with five indices (0-4) to hold five integers
- int[] intArray = new int[5];
- //manually add some values to the array (this can be done using a "for loop", as well)
- intArray[0] = 1;
- intArray[1] = 2;
- intArray[2] = 3;
- intArray[3] = 4;
- intArray[4] = 5;
- //Now that we have added five integers to our array, we can print it using a "for loop", rather than
- //having to write five separate "System.out.println()" statements
- for(int i = 0; i <= 4; i++){
- //print out the value stored in the "ith" index of the "intArray" array
- System.out.println(intArray[i]);
- }
- }
- }
Add Comment
Please, Sign In to add comment