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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:32:09+00:00 2026-05-13T13:32:09+00:00

Hey there. Java beginner here :) Well, I’m having a few troubles with this

  • 0

Hey there. Java beginner here 🙂 Well, I’m having a few troubles with this program: http://pastie.org/private/sfqqnqwxtpgtuhswpqepw

1) I want my program to split up the “input” array into an oddList, evenList and negativeList set of arrays. However, when splitting it up, it is adding a bunch of elements as “0”.

2) 0 needs to be added only to the oddList.

3) I can’t figure out how to add the average from averageAndGreater() to the end of the array.

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-05-13T13:32:09+00:00Added an answer on May 13, 2026 at 1:32 pm

    1) Your array is longer than it’s contents, since an array is of fixed length, those extra spots must hold something, which is 0.

    2) You should add 0 to the even list if possible, because the test for evenness (x%2==0) returns true for 0.

    3) You should create the array one longer than you really need int[] oddList = new int[a.length+1]; and use array[array.length-1] = averageAndGreater(input2);

    The simplest way to get an array of the right size would probably be to use the ArrayList class built into Java. You could also remake the array at the end of the method when you know how long it needs to be. Like the following:

    int array = new int[total];
    for (int i=0; i<total; ++i) {
        array[i] = oddList[i];
    }
    
    return array;
    

    Edit:
    Your even and odd lists will include negative numbers, not sure if that was intentional or not, but to reject them use ((a[i] % 2 == 0) && a[i] >= 0) as your even test.

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

Sidebar

Ask A Question

Stats

  • Questions 311k
  • Answers 311k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can make use of the fact that renaming directories… May 13, 2026 at 10:21 pm
  • Editorial Team
    Editorial Team added an answer Try an OnScrollListener May 13, 2026 at 10:21 pm
  • Editorial Team
    Editorial Team added an answer Flash's (and hence Flex's) htmlText doesn't officially support tables to… May 13, 2026 at 10:21 pm

Related Questions

In Java (And in general) is there a way to make a class so
Hey all, my Computational Science course this semester is entirely in Java. I was
Hey, I've been developing an application in the windows console with Java, and want
hey, I have this code that should save a java.util.Vector of custom serializable classes:
Hey yall, I have a wicket- and also a server-related question: We built a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.