Array program
previous NextExample 2
import java.util.Scanner;
class Raj{
public static void main(String[] args) {
int arr[] = new int[5];
Scanner sc = new Scanner(System.in);
System.out.println("Enter elements of the array");
for(int i =0; i<5;i++)
{
System.out.print("Enter value for arr["+i+"] - ");
arr[i] = sc.nextInt();
}
System.out.println("Content of the array - ");
for(int i = 0; i<5;i++)
{
System.out.println("Value ot arr["+i+"]"+arr[i]);
}
}
}
Output :
Enter elements of the array Enter value for arr[0] - 4 Enter value for arr[1] - 5 Enter value for arr[2] - 6 Enter value for arr[3] - 7 Enter value for arr[4] - 8 Content of the arry - value at arr[0]4 value at arr[1]5 value at arr[2]6 value at arr[3]7 value at arr[4]8