Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8229845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:56:12+00:00 2026-06-07T16:56:12+00:00

Im still starting out in java – and any guidance would be great on

  • 0

Im still starting out in java – and any guidance would be great on this. I’m basically hoping to create an array, then assign values to that array in a for loop. The code I have at the moment is:

int i;
int[] testarray = new int[50];

for (i = 0; i <=50; i++) {  
testarray[i]=i;
}

All i wanna do is make an array with each entry the number of the iteration (using this method)
I know its really simple, but I feel as if I have missed something important during learning the basics!
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:56:14+00:00Added an answer on June 7, 2026 at 4:56 pm

    Everything is fine except the stop condition:

    for (i = 0; i < 50; i++) {  
    

    Since your array is of size 50, and indices start at 0, the last index is 49.

    You should reduce the scope of i, avoid hard-coding the length everywhere (don’t repeat yourself principle), and respect the camelCase naming conventions:

    int[] testArray = new int[50];
    
    for (int i = 0; i < testArray.length; i++) {  
        testArray[i]=i;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I'm still in the starting phase, and I know how to use Console.WriteLine
I'm still starting out with PyQt with QtDesigner using eric4 (and still studying python
I'm just starting to figure out regex and would love some help trying to
Disclaimer : I'm still starting out with MVC3 (and OAuth in particular). I might
I've been trying to figure this out but its starting to make me want
So starting to learn C++. I am a pretty decent (not great) Java Programmer
This question should be rather easy for any Java developer. I swear I looked
guys sorry for being so noob but im still starting yet with my php,
I'm starting off with NHibernate now and I still don't have a testable environment.
I'm starting to understand git but I'm still having some trouble with the abstraction.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.