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 6927989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:07:32+00:00 2026-05-27T11:07:32+00:00

I am trying to create an array with ‘total’ amount of numbers between min

  • 0

I am trying to create an array with ‘total’ amount of numbers between min and max. And then, sort them using bubble sort. When i execute, i get all zeros. Could someone find what is going wrong? A prompt reply would be appreciated.

import java.util.*;
import java.util.Random;

public class final_project 
{ 
    public static void main(String[] args) 
    { 
        int numbers[]; 
        int i, min, max, total; 
        int num;
        Scanner scan = new Scanner(System.in);

        System.out.println("Please enter a minimum random value");
        min = scan.nextInt();
        System.out.println("Please enter a maximum random value");
        max = scan.nextInt();
        System.out.println("Please enter the amount of random numbers");
        total = scan.nextInt();

        numbers = new int[total];


        i = 0;
        total = 0;
        while ( i < total )
        {
            num = min + (int)(Math.random()*max);;
            numbers[i] = num;  
            total += num; 

            i += 1; /* i = i + 1; */
        }


        bubbleSort(numbers, numbers.length); 
        System.out.println("Your Sorted Array Is: "); 
        for(i=0; i<numbers.length; i++) 
        { 
            System.out.print(numbers[i] + " "); 
        } 

    }



    private static void bubbleSort(int[] numbers, int length) 
    { 
        int temp, counter, index; 

        for(counter=0; counter<length-1; counter++) 
        { 
            for(index=0; index<length-1-counter; index++) 
            { 
                if(numbers[index] > numbers[index+1]) 
                { 
                    temp = numbers[index]; 
                    numbers[index] = numbers[index+1]; 
                    numbers[index+1] = temp; 
                } 
            } 
        } 
    } 
}
  • 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-27T11:07:33+00:00Added an answer on May 27, 2026 at 11:07 am

    Change

    while ( i < total )
    

    to

    while ( i < numbers.length )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to create an array of tm* structs, and then return them at
I'm trying to create an array, and then sort the objects by time, from
I'm trying to create an array in MIPS Assembly, and then add all the
I am trying to create an array with different hrefs to then attach to
I'm trying to create an array of structs as a sort of rudimentary cache.
So as the question states, im trying to create an array using a for
I am trying to create an array of size 2^25 in c and then
I am trying to create an array of strings in C using malloc .
I'm using the iPhone SDK (3.0) and I'm trying to create an array of
I am trying to create array of buttons, then making one onClick event for

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.