Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the return value of the java method

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to understand the return value of the java method". In the daily operation, I believe many people have doubts about how to understand the return value of the java method. The editor consulted all kinds of data and sorted out a simple and easy-to-use operation method. I hope it will be helpful for you to answer the doubt of "how to understand the return value of the java method". Next, please follow the editor to study!

1. The return value of a method refers to the result of executing the code in the body of a method. The premise is that this method may produce results.

2. The function of the return value: to receive the result so that it can be used in other operations.

If a method has a return value, it must be returned using the keyword return, which is the type of the method.

Example

Package com.jredu.ch09;import java.util.Arrays;import java.util.Scanner;/** * method with return value * get the sorted array * @ author Administrator * * / public class Ch05 {public Scanner input;public String [] name = new String [5]; public Ch05 (Scanner input) {super (); this.input = input } public String [] student () {/ / the return value type is an array System.out.println ("Please enter the names of 5 students"); for (int I = 0; I < name.length; iTunes +) {name [I] = input.next ();} Arrays.sort (name); / / an array to sort System.out.println ("* sorted *"); return name / / return array name} public static void main (String [] args) {Ch05 d = new Ch05 (new Scanner (System.in)); System.out.print (Arrays.toString (d.student ()) + "\ t") / / d.student (): call the return value / / Arrays.toString (d.student ()): convert the array to a string}} at this point, the study on "how to understand the return value of the java method" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report