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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:20:39+00:00 2026-06-16T00:20:39+00:00

i’m struggling a bit with getting array values from one method into another without

  • 0

i’m struggling a bit with getting array values from one method into another without repeating the method over again (the method obtains judges scores using getScannerInput (we have to use it at my uni instead of other options :-/ ).

My program is the following;

public class mark4

{

static int SIZE = 10; // Define array size
static int classMarks[] = new int [SIZE]; // Initialise array classMarks[]
static double max = 0; 
static double min = 0;
static double total = 0;
static double averagescore = 0;
static int pass = 0;

 public static int[] getMarks()
{
    int[] classMarks = new int [SIZE];

    for(int i = 0; i< classMarks.length; i++) // Start input loop to obtain marks
    {
        classMarks[i] = getScannerInput.anInt("Please enter students mark: ");
    }


        System.out.print("\nThe marks for this class are; "); // Output initial line to be completed with students marks

    for(int i=0; i<classMarks.length; i++) // Start output loop to output students marks
    {
        System.out.print(classMarks[i] + ", "); // Output marks separated by a comma and a space

    }

    return classMarks;
}

public static double averagescore(){

    for(int i=0; i<classMarks.length; i++) // Start loop to calculate total of all marks.
    {
        total = classMarks[i] + total; // Calculate total of array by traversing and adding to 'total' variable each time
        averagescore = total / classMarks.length; // Divide array total by array length to find average

    } // end average loop

        return averagescore;    

}

public static double min(){

    min = classMarks[0]; // Set min to first value of array to compare to rest


    for(int i=0; i<classMarks.length; i++) // Start loop to calculate minimum and maximum scores
    {
            if(classMarks[i] < min) // Compare values on each iteration, if value is less than current 'min' value, replace min with new value
                    min = classMarks[i];

    } // end minloop

    return min;
}

public static double max(){

    max = classMarks[0]; // Set max to first value of array to compare to rest


    for(int i=0; i<classMarks.length; i++) // Start loop to calculate minimum and maximum scores
    {
        if(classMarks[i]>max) // Compare values on each iteration, if value is greater than current 'max' value, repalce max with new value
                    max = classMarks[i];

    } // end max loop

    return max;
}

public static int pass(){

    for(int i=0; i<classMarks.length; i++) // Start loop to calculate how many students passed with a mark of 8 or higher
    {
            if( classMarks[i] >= 8 ) // Compare the current score in each iteration to 8 to see if it is more than or equal to the pass mark

                    pass++; // If current value is greater than or equal to pass mark, add one to pass counter.

    } // end pass loop

    return pass;
}

public static void main (String args[])
{

    int[] classMarks = getMarks();
    double averagescore = averagescore();
    double min = min();
    double max = max();
    int pass = pass();

                System.out.print("\nThe number of students who passed the exam is " + pass);
                System.out.printf("\nThe class average correct to 1 decimal place is: %4.1f", averagescore); // Output average score to 1 decimal place
                System.out.printf("\nThe lowest mark obtained in this class was: %3.1f", min); // Output lowest score to one decimal place (in case of half marks...)
                System.out.printf("\nThe highest mark obtained in this class was: %3.1f", max); // Output highest score to one decimal place (in case of half marks...)


} // end main

} // end class

The program compiles correctly, but the results I get are all 0 or 0.0, suggesting that the methods aren’t taking the figures input during the getScores() method.

If I try to define the results for classMarks[] inside the methods using;

int[] classMarks = getMarks();

it repeats the whole getScores() method and asks for the results again every time it encounters a method in the main.

I’m aware this is probably a fairly simple answer, but we had to do this as a question in an assessment, but i missed the lectures on methods and arrays and i’m struggling a bit with some minor elements.

Any help would be much appreciated!

  • 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-16T00:20:39+00:00Added an answer on June 16, 2026 at 12:20 am

    In your main method you are declaring classMarks, which is hiding the static classMarks you have at the class level. You are also declaring another classMarks array within your getMarks method, so your scanner is never reading into the shared classMarks array, only into the local array in getMarks, which is then returned and placed in the local classMarks variable in main, but never getting into your static variable that is referenced by every other method in the class.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string

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.