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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:35:16+00:00 2026-05-31T06:35:16+00:00

Input array: [200, 8, 10, 60, 30, 80]; Output am getting: [200, 10, 60,

  • 0
Input array: [200, 8, 10, 60, 30, 80];
Output am getting: [200, 10, 60, 80, 30, 8]; 
Output required: [200, 60, 80, 8, 10, 30];

Objective: If the array element is less than 50 then move it to the bottom of the array but maintain the order of the array (by shifting left before inserting the less than 50 element to the bottom). An example is as shown above.

Problems:
1. Even though 10 is less than 50 it is still not moved to the bottom.
2. 8 should be before 30 because it will be moved first to the bottom and then 30 is moved. But 8 is at the last.

My Java code:

import java.util.*;
public class chapte1_17
{
  public static void main(String[] args)
  {
    int list[] = new int[] {200, 8, 10, 60, 30, 80};
    int length = list.length;
    int value = 50;
    int temp;
    //System.out.println(length);
    for ( int i = 0 ; i < list.length ; i++ )
    {
        if (list[i] <  value) {             
            int remIndex = i;
            temp = list[i];
            //System.out.println(remIndex);
            //System.out.println(temp);

            for ( int j = remIndex ; j < list.length - 1 ; j++ )
            {
                list[ j ] = list[ j + 1 ] ;

            }
            list[list.length -1] = temp;
        }

        System.out.println(list[i] + "");
    }
  }
}

I am new to sorting and Java – any help would be 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-31T06:35:17+00:00Added an answer on May 31, 2026 at 6:35 am

    First, your output is wrong, you should loop over array when the first for loop finishes.

        for (int i = 0; i < list.length; i++) {
            //code
        }
        for (int i = 0; i < list.length; i++) {
            System.out.println(list[i] + "");
        }
    

    Second thing is the logic of the moving, try something like this:

    int list[] = new int[] { 200, 8, 10, 60, 30, 80 };
        int length = list.length;
        int value = 50;
        int temp;
        int actual_i = 0;
        // System.out.println(length);
        for (int i = 0; i < list.length; i++) {
            if (list[i] < value && actual_i < list.length - 1) {
    
                int remIndex = i;
                temp = list[i];
                // System.out.println(remIndex);
                // System.out.println(temp);
    
                for (int j = remIndex; j < list.length - 1; j++) {
                    list[j] = list[j + 1];
    
                }
                list[list.length - 1] = temp;
                i--;
            }
            actual_i++;
    
        }
        for (int i = 0; i < list.length; i++) {
            System.out.println(list[i] + "");
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how to take user input in Array using Java? i.e we are not initializing
I have byte array as input. I would like to convert that array to
I have an array of input controls garnered like so: var hiddenInputs = $(input[id^='Unanswered'])
I have an array of input strings that contains either email addresses or account
I need to split my string input into an array at the commas. Is
Input: 1) A huge sorted array of string SA; 2) A prefix string P;
Given following Ruby statements: (Read input and store each word in array removing spaces
I am trying to log some input values into an array via jquery and
What would be the best way to fill an array from user input? Would
What is the prefered method for creating a byte array from an input stream?

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.