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

  • SEARCH
  • Home
  • 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 7496631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:42:14+00:00 2026-05-29T18:42:14+00:00

I’m trying to write an application which will populate an array with random numbers.

  • 0

I’m trying to write an application which will populate an array with random numbers. Everything seems to work fine until I try to enter the for loop in my populateArray method.

import java.util.Random;

public class PerformanceTester {

//takes an empty array, but the size must be allocated BEFORE passing 
//to this function. Function takes a pre-allocated array and input size.
public static int[] populateArray(int[] inputArray, int n) {

    //Create the number generator
    Random generator = new Random();

    int length = inputArray.length;
    System.out.println("Inputted array is length: " + length);

    for (int i = 0; i == length; i++) {
        // for debugging purposes: System.out.println("For loop entered.");
        int random = generator.nextInt((2 * n) / 3);
        // for debugging purposes: System.out.println("Adding " + random + " to the array at index " + i);
        inputArray[i] = random;

    }
    return inputArray;
    }

public static void main(String[] args) {

    int[] input;
    input = new int[10];
    int[] outputArray = populateArray(input, 10);
    System.out.print(outputArray[0]);

}
}

As shown by my output, the compiler clearly enters the method (when called on line 29) but seems to stop all execution when the for loop is reached. I’m 100% sure that my loop has proper initialization and termination operators, because length is equal to ten.

I’m honestly stumped, but like most cases, I’m certain its a very simple answer. My output is below:

Inputted array is length: 10
0 //The array is not populated with numbers, so all indexes of the array return zero.

Any and all help is greatly appreciated.

  • 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-05-29T18:42:16+00:00Added an answer on May 29, 2026 at 6:42 pm

    Surely you meant your loop test to be this right?

    for (int i = 0; i < length; i++) {
    

    Otherwise, i == length will never be true (unless length == 0) and it will never enter the loop.

    You also could have used:

    for (int i = 0; i != length; i++) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

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.