return-English literal translation returns, meaning to return;
In Java, return means returning data. In Java, a method is usually defined to implement a certain function.
package sreturn; public class Sreturn { public int Sreturn(int a, int b) { int c = a + b; return c; } }
The above code implements addition c=a+b; what is returned is an int type c. In other words, this method implements a simple addition function, and returns us a value of c after implementation (note that the return only gives the user a usable data type, and does not output the system). If there is no return to return to us the result of this addition, then our code and method will be meaningless.
The following are three examples of returning different data types:
1.public String Sreturn2(){ String name = "高兴"; return name; } 2.public double Sreturn3(double c,double d){ double f = c/d; return f; } 3.public boolean Sreturn4(){ boolean a= false; return a; }
The above three examples implement different types of return values string, double and Boolean respectively.
So when to use return? Do you use return every time? What does it look like without using return?
There are two ways to use return in java:
1. Return a value of the corresponding type; //If the method declares a certain data type, it must return the same data type.
2. End the execution of the program; //A single return statement indicates the end of execution of the statement.
The second example is as follows:
if(a>4){ return; } else{ System.out.println("xxxx"); } 当程序不需要返回值时,我们需要使用void关键字如下: public void Speaking(){ System.out.println("我们会说话"); }
This example uses the void keyword. We don’t need to return any value. It is just a method. When we use this method, it will output "we can talk". When the void keyword appears in the program, it means that there is no need to return or return.
The return and void keywords can control the flow of the method.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version
God-level code editing software (SublimeText3)