Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. public class Array {
  6.  
  7. public static void main(String[] args) throws IOException
  8. {
  9. BufferedReader ch=new BufferedReader(new InputStreamReader(System.in));
  10.  
  11. System.out.println("Hello Worldn");
  12.  
  13. System.out.println ("nEnter the number of elements:");
  14. int n=Integer.parseInt(ch.readLine());
  15.  
  16. int a[]=new int[n];
  17.  
  18. for (int i=1;i<=n;i++)
  19. {
  20. a[i]=Integer.parseInt(ch.readLine());
  21. }
  22. System.out.println ("nThe elements are as follows:n");
  23.  
  24. for(int i=1;i<=n;i++)
  25. {
  26. System.out.println (a[i]+"t");
  27. }
  28.  
  29.  
  30. }
  31. }
  32.  
  33. Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
  34. at Array.main(Array.java:26)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement