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

Related Questions

hey there, Im having problems displaying my results in this program but the program
Hey, how do i make my java SWT list look like here http://flavio.tordini.org/minitunes I
Hey there, I am trying to get my signout button to work. This is
Hey there, I'm sort of new to Objective-C, and well, programming in general. I
Hey there. I'm trying to write a small program that will read the four
hey there guys and girls i have this code that saves json as a
hey there i have this code that should save a file from sql server
Possible Duplicate: Java REPL shell Hey, Is there any way to execute Java code
Hey, There's a lot of posts on here about read barcodes but I want
Hey all, this will contain a few questions since I don't seem to really

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.