Q:

Write a java program that declares an array of 10 integers. Then, assigns values to each array element

0

Exercise 2: Write a java program that declares an array of 10 integers. Then, assigns values to each array element, which is the value of the element’s index multiplied by 2. Eventually, print the array elements using for loop.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

public class Main
{
	public static void main(String[] args) {
	    int []arr1=new int[10];
	    for(int i=0;i<arr1.length;i++)
	    {
	        arr1[i]=i*2;
	    }
	    
	    //printing array elements
	    for(int i=0;i<arr1.length;i++)
	    {
	        System.out.println(arr1[i]);
	    }
	}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now