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

  • Home
  • SEARCH
  • 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 9210083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:59:17+00:00 2026-06-18T00:59:17+00:00

In the following code the method array1 won’t return the avarage because its return

  • 0

In the following code the method array1 won’t return the avarage because its return type is void.

I know what void means but can someone explain to me what is a void result type and how to make this method return the avarage:

public class JavaApplication4 {
    public static void main(String[] args) {
    int[] a = {1,2,3,4};

    double result = array1 (a);
}

public static array1 (int[] b) {
    double avarage;
    int total = 0;
    for (int x:b) {
        total += x;
    }

avarage = total / b.length;
return avarage;
}
  • 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-18T00:59:18+00:00Added an answer on June 18, 2026 at 12:59 am

    A return type of void means that a method doesn’t return anything. This is useful when you want to preform an operation on an array, but there isn’t any value associated with the operation. For example, say that you wanted to swap the first and last element in an array, you could write some method like this (ignore the necessary error checking)

     public void swapArrayLocs(int[] swapping){
          int temp = swapping[0];
          swapping[0] = swapping[swapping.length - 1];
          swapping[swapping.length - 1] = temp;
     }
    

    When you call this method, you’re not expecting any sort of result from it, you’re expecting your program to just take care of business and continue executing.

    In this case, you actually want your array1(int[]) method to make its available to the rest of the program. You do this by specifying the return type of the function, which tells the rest of the program what type of information you expect that function to return. In your case, you’d do this by changing your method declaration to.

    public static double array1(int[] b){
        //the same method body
    }
    

    Note how in this case the word double is inserted after static. This tells the calling function that when it executes array1, the method will give back a value of type double. Contrast this with what you had before which said that the method would not give back any type of information.

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

Sidebar

Related Questions

I have the following code (calling a method returning IEnumerable): FibonacciWithLinq.Skip(delegate() { return 5;
i have the following code that won't compile because of generic problems. It comes
As following code I wanna send matrix1Col and matrix2Col to multiply method. But it's
I'm using the following method in my code: - (NSMutableArray *) newOrderedArray:(NSMutableArray *)array ByKey:(NSString
I am using following code in viewDidLoad method CLLocationManager *locationManager = [[CLLocationManager alloc] init];
The following code examines the behaviour of the float() method when fed a non-ascii
I have the following code in my viewDidLoad method. This is a uiviewcontroller with
I have the following code: LPCTSTR strPermission = Method(); if (strPermission == L0) {
I have the following code in my controller action method: if (User.Identity.IsAuthenticated) { //
I have the following code which utilises Guava's Files.readLines() method: List<String> strings = Lists.newArrayList();

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.