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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:03:54+00:00 2026-06-18T06:03:54+00:00

In the below code, I am getting an output on the basis of the

  • 0

In the below code, I am getting an output on the basis of the arraylist I have defined myself.

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class DinoMania {

public static void main(String[] args) {
    List<Dinosaur> dinoList = new ArrayList<Dinosaur>();
    Dinosaur d1 = new Dinosaur(1970, 1985);
    Dinosaur d2 = new Dinosaur(1980, 1981);
    Dinosaur d3 = new Dinosaur(1990, 2015);
    Dinosaur d4 = new Dinosaur(2000, 2007);
    Dinosaur d5 = new Dinosaur(2010, 2012);
    Dinosaur d6 = new Dinosaur(2020, 2030);
    Dinosaur d7 = new Dinosaur(2030, 2035);

    dinoList.add(d7);
    dinoList.add(d6);
    dinoList.add(d5);
    dinoList.add(d4);
    dinoList.add(d3);
    dinoList.add(d2);
    dinoList.add(d1);

    //System.out.println(dinoList);

    Collections.sort(dinoList);

    //System.out.println(dinoList);
    int maxCount = 0;
    List<String> ls=new ArrayList<String>();

    for (Dinosaur dino : dinoList) {

        // System.out.println("start date" + dino.getStartDate());
        // System.out.println("end date"+ dino.getEndDate());
        int count = 0;
        for (Dinosaur dino2 : dinoList) {

            if (dino2.getStartDate() <= dino.getEndDate()
                    && dino2.getEndDate() >= dino.getStartDate())
                count++;

        }
        //System.out.println(count);

        if (maxCount < count) {
            maxCount = count;
            ls.clear();
            ls.add(dino.getStartDate()+"-"+dino.getEndDate());
        }

        else if(maxCount==count)

        {
            ls.add(dino.getStartDate()+"-"+dino.getEndDate());
        }
    }
    //System.out.println(maxCount);

//System.out.println(ls);

System.out.println("Max no of Dinos alive at the same time :"+maxCount);
}

}

I would like to know how do I define arraylists dynamically, when the user inputs from the console

  • 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-18T06:03:55+00:00Added an answer on June 18, 2026 at 6:03 am

    you can use something like this:

    Scanner s = new Scanner(System.in);
        System.out.println("please enter 5 records");
        List<Dinosaur> dinoList = new ArrayList<Dinosaur>();
    
        for (int i = 0; i < 5; i++) {
            int num1 = s.nextInt();
            int num2 = s.nextInt();
            Dinosaur d = new Dinosaur(num1, num2);
            dinoList.add(d);
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the code below for getting a list of child processes on windows
I'm getting this error message with the code below: class Money { public: Money(float
When i run the below code I am getting error like ex = {The
for the Given below code after int Input Value of 46348 i am getting
I am getting an compilation error not a statement for the below code. Not
In the below code how to remove the hyperlink after getting the innerHTML :
I am using the below code, but I am not getting that why it
From the code below I am getting a cell value from the selected row
Per the code below, I am getting the following message. I am fairly certain
Getting vector iterator not deferencable for code below, but I don't see why. 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.