Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Java Method Return Value 
 

The return statement is used to return the value within the body of method. The method declared void does not return any value.

 

Java Method Return Value

                         

Java  method Return Value return to the code when it -

  1. When  it completes all the statements in the method
  2. When it  reaches a return statement
  3. throwing  an exception, whichever occurred first.

The return statement is used to return the value within the body of method. The method declared void does not return any value. In case you try to get the return value from void .the code show you a compiler error. 

The method that is not declared void must contain a return statement with the  corresponding return value.:

Understand with Example

The Tutorial illustrates a code that help you in understanding JAVA method Return Value. In this Program we have a class Return Value, Inside the class we have a main method .The code show you how to get biggest number, for this we define a public static int GetBiggestNumber ( ) accept a int num1,num2,num3 as parameter. The if conditional operator evaluate and compare the numbers and return the biggest number. Finally the println print the get Biggest Number  is 20 from 10,15,20.in the command prompt.

Here is the code:


class ReturnValue
{
public static void main (String[] args)
{
System.out.println("The Biggest Number is: "+GetBiggestNumber(101520));
}
public static int GetBiggestNumber (int num1, int num2, int num3)
{
int biggest = 0;
if ((num1 > num2&& (num1 > num3))
biggest = num1;
else
if ((num2 > num3&& (num2 > num1))
biggest = num2;
else
biggest = num3;
return biggest;
}
}

Output will be displayed as:

Download Source Code

                         

» View all related tutorials
Related Tags: c error com compiler method sed get compile value state return pil id case cas show with mpi statement to

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.