Java Basics---The use of method with parameter return values in Java (40)

Source: Internet
Author: User

Use of the return value method with a parameter in Java

If the method contains both parameters and return values, we are called methods with the return value of the parameter.

For example: The following code, which defines a show method with a parameter name, returns a String result after the method executes

650) this.width=650; "style=" width:340px; src= "Http://img.mukewang.com/537dce1e0001b09305200123.jpg"/>

Call a method with a parameter return value:

650) this.width=650; "style=" width:340px; src= "Http://img.mukewang.com/537dce3e0001226f04870138.jpg"/>

Operation Result: 650) this.width=650; "src=" http://img.mukewang.com/537dcf090001068401350025.jpg "/>


Code:

Import Java.util.Arrays;

public class HelloWorld {
public static void Main (string[] args) {
HelloWorld Hello = new HelloWorld ();
Int[] scores={79,52,98,81};

Call the method, pass in the score array, and get the number of scores
int Count=hello.sort (scores);

System.out.println ("A total of" +count+ "score information! ");
}

/*
* Function: Sort and output the exam results, return the number of results
* Defines a method that contains an integer array parameter, passing in an array of scores
* Use the Arrays class to sort the result array and output
* Returns the number of elements in the array after the method executes
*/
public int sort (int[]scores) {
Arrays.sort (scores);
System.out.println (arrays.tostring (scores));

Returns the number of elements in an array
return scores.length;
}
}


Operation Result:

[52, 79, 81, 98]
A total of 4 results information!

This article is from "Ghost" blog, please make sure to keep this source http://caizi.blog.51cto.com/5234706/1548009

Java Basics---The use of method with parameter return values in Java (40)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.