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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:08:21+00:00 2026-06-13T00:08:21+00:00

I’m been assigned to make a program that gets 100 random integers between 0-25

  • 0

I’m been assigned to make a program that gets 100 random integers between 0-25 and store them in an array.
I then have to call upon 2 methods to split the evens and the odds (very typical).
So I tried the ArrayList thing (I jut learnt it) and it seemed fine (I was following tutorial and things online) until I ran into this:
Unit8.java uses unchecked or unsafe operations

My code is this:

    import java.util.*;
    import java.awt.*;

    public class Unit8
    {
public static void main (String [] args)
{
    //create an array for original 100 integers
    //create a 2D array for evens and odds
    //split them up using 2 methods

    int[] originalArray = new int[100];
    ArrayList even = new ArrayList(1);
    ArrayList odd = new ArrayList(1);

    for (int x = 0; x < originalArray.length; x++)
    {
        originalArray[x] = (int)(Math.random() * 25);
    }

    evensDivider(originalArray, even);
    oddsDivider(originalArray, odd);
}

public static void evensDivider (int[] e, ArrayList even)
{


    for (int y = 0; y < e.length; y++)
    {
        if (e[y]%2 == 0)
            even.add(e[y]);
    }

    System.out.println("The evens are: " + even);
}

public static void oddsDivider (int[] o, ArrayList odd)
{


    for (int z = 0; z < o.length; z++)
    {
        if (o[z]%2 == 1)
            odd.add(o[z]);
    }
}

}

With the errors occurring specifically at:
even.add(e[y]);
and
odd.add(o[z]);

Please Help me out with this, I’ve tried my best to make it clear and easy to understand.

  • 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-13T00:08:22+00:00Added an answer on June 13, 2026 at 12:08 am

    This is because you are using ArrayList with raw type. And you are adding a specific type to it.

    Raw type ArrayList would expect element of type Object. If you add any other type, then Compiler would not know exactly what type you are storing. So, it gives you unchecked or unsafe operations to warn you that you might be doing something wrong.

    You should better create a Generic ArrayList:-

    List<Integer> evenNumbers = new ArrayList<Integer>();
    

    Also, change it in your method signature: –

    public static void evensDivider (int[] e, List<Integer> evenNumbers)
    

    PS: – You should always have a reference of interface type if you have one. I mean use List in place of ArrayList

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I have an array which has BIG numbers and small numbers in it. 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.