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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:25:18+00:00 2026-06-01T04:25:18+00:00

Hi I have been working on a solution for days, and I’ve been trying

  • 0

Hi I have been working on a solution for days, and I’ve been trying to figure it out on my own but I just can’t.

I have an ArrayList and I want to swap the elements in it. But I want to compare the list in halves. So say if the list had 8 elements in it, I would want to compare the first element in the first half of the list with the first element in the second half of the list.
So list[0] with list[4] and if 4 is bigger than 0, i want to swap them, then i want to increment 0 and by 1, and half the list by one, until i = 4.
I have to run it from the command line.

 import java.util.Arrays;
 import java.util.ArrayList;
 import java.util.Scanner; 
import java.util.Collections;

public class TennisTournament {
     public static void main (String [] args) {
    Scanner input = new Scanner(System.in);
    ArrayList <Integer> nums = new ArrayList<Integer>();
    while (input.hasNextInt()) {
      nums.add(input.nextInt());
    }
    tournament(nums);   }
     public static void tournament(ArrayList <Integer> list) {
    int midPoint = list.size()/2; // returns the index number of half of the lists size
    for (int i = 0; i < midPoint; i++) { // while is bigger than mid point, increment by one
      if (list.get(i) < list.get(midPoint)) {
          Collections.swap(list, i, midPoint);
          System.out.print(list);
      }
    }
    System.out.println(list);   }

}

This is what I have so far, but when I run it from the command line, it just returns an ordinary list, and I’m completely stumped. I would much rather use a loop than the collections method as it is not a style of programming i am particular familiar with.

  • 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-01T04:25:19+00:00Added an answer on June 1, 2026 at 4:25 am

    Look at midPoint – it never changes inside the loop. You’re continually exchanging the i-th element (provided that the “if” condition is true) with the midPoint. No element after midPoint is ever touched.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on this issue for a few days now and can't
I've been working on this for days and I can't find a proper solution,
I've been trying to figure this problem out for the last 2 days already,
I have been working with thread since last few days.I want to stop my
I have been working with relational databases for sometime, but it only recently occurred
I have been working with Struts for some time, but for a project I
Afternoon, I have been working with CKEditor and CKFinder for the last few days
Why would my VS solution lose its TFS bindings suddenly? I have been working
I have been searching for a solution for the past two days now. I
I have been working on this problem for close to 4 days now. I

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.