Last active
August 29, 2018 16:15
-
-
Save xnorcode/249746906a941edc89792ac1b383695f to your computer and use it in GitHub Desktop.
Simple Array Manipulation in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
// Method 1 | |
// create array of already known numbers | |
int[] numbers = {10,2,5,8,37,6}; | |
// printing all numbers | |
for(int i = 0; i < numbers.length; i++){ | |
System.out.println(numbers[i]); | |
} | |
// Method 2 | |
// create an empty array with 3 slots | |
String[] strings = new String[3]; | |
// input strings to the array | |
for(int i = 0; i < 3; i++){ | |
strings[i] = "String"+i; | |
} | |
// printing the strings | |
for(String s : strings){ | |
System.out.println(s); | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment