Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to add elements in array in java using for loop

int[] nums = new int[5];
for(int i = 0; i < nums.length; i++){
  nums[i] = i + 2;
  System.out.println(nums[i]);
}
/*
  OUTPUT:
  2 3 4 5 6
  each time i is increased by 2
*/
Comment

PREVIOUS NEXT
Code Example
Java :: reading csv file in java 
Java :: java random unique number 
Java :: java scanner 
Java :: execute code after delay java 
Java :: java foreach 
Java :: sorting the characters of a string in java 
Java :: jframe visibility 
Java :: How to invoke sendKeys() method for Integer values using Selenium and Java 
Java :: java random word from list 
Java :: java encrypt string 
Java :: android sharedpreferences 
Java :: java iterate over list 
Java :: initialize arraylist in 1 line in java 
Java :: get type java 
Java :: how do i print text in java 
Java :: how to use input in java 
Java :: how to write deserlizer java 
Java :: java image draw 
Java :: how to read a excel file in java 
Java :: java create list integer range 
Java :: simple login password and username java 
Java :: android list[i] 
Java :: java list distinct by key 
Java :: getcurrencyinstance java example 
Java :: set ImageView size programmatically android 
Java :: Java Create LinkedList in Java 
Java :: operador ternario java 
Java :: Java Converting int to double 
Java :: java string regexp replace 
Java :: android studio alert dialog box 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =