By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,237 Members | 1,228 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,237 IT Pros & Developers. It's quick & easy.

How do I create a user defined array size?

P: 2
I'm trying to create a program that prompts the user for a number N. This number will be used to prompt the user N times to provide an integer.
Apr 27 '13 #1
Share this Question
Share on Google+
1 Reply


P: 59
Expand|Select|Wrap|Line Numbers
  1.  
  2. Scanner sc = new Scanner();
  3.  
  4. System.out.println("Enter size of your array");
  5. int n = sc.nextInt();
  6.  
  7. int a[] = new int[n];
  8.  
  9. System.out.println("Enter values);
  10. for(int i = 0; i < a.length; i++)
  11. {
  12.   a[i] = nextInt();
  13. }
Apr 28 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.