fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12.  
  13. Scanner input = new Scanner (System.in);
  14. System.out.println("Enter no. of elements in array ");
  15. int n = input.nextInt();
  16.  
  17. int[] arr = new int[n];
  18. System.out.println("Array length set to "+n);
  19. for (int i=0; i<n; i++)
  20. {
  21. System.out.println("Enter value for index "+i);
  22.  
  23. arr[i] = input.nextInt();
  24. System.out.println(arr[i]+" Value saved at index "+i);
  25. }
  26. }
  27. }
Success #stdin #stdout 0.13s 321088KB
stdin
2
1
3
stdout
Enter no. of elements in array 
Array length set to 2
Enter value for index 0
1 Value saved at index 0
Enter value for index 1
3 Value saved at index 1