Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Get percent of failing grades from an array

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Location
    Minneapolis, MN
    Posts
    1
    My Mood
    Lurking
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Get percent of failing grades from an array

    Hello everyone! I was working on a problem that I thought would be quite simple, but for some reason, my code won't return any percentage other than 0. I am supposed to return the percentage of grades that are less than 60 from an array of grades. This is what I came up with:

    public class FunctionalityTest
    {
        public float getPercentFailing(float[] grades)
        {
            int failed = 0;
            for (int i = 0; i < grades.length; i++)
            {
                if (grades[i] < 60f) 
                {
                    failed += 1;
                }
            }
            return failed / grades.length;
        }
    }

    Any help or advice would be very much appreciated!
    Last edited by thom4065; February 23rd, 2013 at 03:48 PM. Reason: Thought I might not have been specific enough, so I added a few more lines of code.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,071
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Get percent of failing grades from an array

    Integer arithmetic: 9/10 = 0
    float arithmetic: 9.0/10 = 0.9

    Make one of the numbers a float to get float arithmetic
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    thom4065 (February 23rd, 2013)

Similar Threads

  1. Trying to fix my code but I keep failing :(
    By james2013 in forum Android Development
    Replies: 4
    Last Post: May 14th, 2013, 06:40 AM
  2. Creating a java program to calculate what grades i need?
    By Stinger25 in forum Java Theory & Questions
    Replies: 2
    Last Post: December 1st, 2012, 01:04 AM
  3. Print Student average, high, and low grades through array?
    By MLeclerc182 in forum Object Oriented Programming
    Replies: 2
    Last Post: May 10th, 2012, 06:12 AM
  4. Students/Grades
    By ruffu054 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: September 12th, 2011, 10:42 AM
  5. Grades project/arrays, loops
    By rochla16 in forum Collections and Generics
    Replies: 1
    Last Post: March 29th, 2011, 12:26 AM