// Create an array with room for 100 integers
int[] nums = new int[100];
// Fill it with numbers using a for-loop
for (int i = 0; i < nums.length; i++)
nums[i] = i + 1; // +1 since we want 1-100 and not 0-99
// Compute sum
int sum = 0;
for (int n : nums)
sum += n;
// Print the result (5050)
System.out.println(sum);
class ArrayUsingLoop
{
public static void main (String[] args)
{
int[] newArray;
newArray= new int[5];
newArray[0] = 1;
newArray[1] = 2;
newArray[2] = 3;
newArray[3] = 4;
newArray[4] = 5;
for (int i = 0; i < newArray.length; i++)
System.out.println("Array Element at index " + i +
" : "+ newArray[i]);
}
}