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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:00:25+00:00 2026-06-12T07:00:25+00:00

I am writing a program that will enter an array of Students with their

  • 0

I am writing a program that will enter an array of Students with their name and gpa’s and return only the failing students. I am unsure how to return an array that will avoid returning null as an element of that array. I.e. if there are 4 students in the initial array, but only 2 are failing, my array is returning: student1, student2, null, null.

Student Jim = new Student("Jim",1.4);
    Student Tom = new Student("Tom",3.0);
    Student John = new Student("John",4.0);
    Student Bill = new Student("Bill",1.2);
    Student[] group1 = {Jim,Tom,John,Bill};

public Student[] getFailing(Student[] students) {
    int i, j;
    Student[] failing = new Student[students.length];
    Student temp;
    for(i=0, j=0; i< students.length; i++){
            if(students[i].getGpa() < 2.0){
                temp = students[i];
                failing[j] = temp;
                j++;
            }

    }
    return failing;
}

My current result when I do a test run in main is:

name = Jim gpa = 1.4
name = Bill gpa = 1.2
null
null
  • 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-12T07:00:27+00:00Added an answer on June 12, 2026 at 7:00 am

    If the only problem is printing the nulls, i.e. it’s OK if your array has null values but you don’t want to see them in your output, then you can leave your method as it is and change your printing code so that it checks for null, and avoid printing them.

    But if you must keep null values out of your array, you can use a dynamically resizing data structure like ArrayList, and get an array out of it using the toArray method.

    Without using ArrayList, since you’re tracking how many Student objects represent failing students with the j variable, after you collect the failing student objects you could create a new array of the desired length, and then fill it with only the non-null students using a loop, or using Arrays.copyOf, or System.arraycopy.

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

Sidebar

Related Questions

I'm writing a program that sends an array through a function (upperhess) that will
I am contemplating writing a program that will move some newly created dirs to
I'm a writing a program that will determine the number of lines, characters, and
I'm writing a simple program that will run entirely client-side. (Desktop programming? do people
I am writing an HTML program that will be accessed by over 500 people
I'm writing a program in C# that will need to store a few Data
I am writing a program, for homework, that will add 2 8-bit binary numbers.
I'm writing a small program in C that will read input from the console.
I'm writing MIPS program that will examine a list of 10 numbers to be
I'm writing a program that, using Rijndael, will encrypt and decrypt files/folders using a

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.