Methods which Return Values in Java Pogramming Language

In this tutorial, you will learn about java methods which return values.

You will learn how to create methods which return values using the return statement, how to call them and process the returned value, how they work, what is the advantage of using them in detail with example

Source code for this video tutorial


package learningJava;

public class Liger {
 public static void main(String[] args) {  
  int i,j,k;
  i = 100;
  j = 200;  
  k = max(i,j);
  System.out.println("maximum number between "+i+" and "+j+" is "+k);  
  System.out.println("smallest number between "+i+" and "+j+" is "+small(i,j));
  printno();  
 }
 
 public static int max(int num1,int num2){  
  int result = 0;  
  if(num1 > num2){
   result = num1;
  }else{
   result = num2;
  }  
  return result;  
 }
 
 
 public static int small(int num1,int num2){  
  if( num1 < num2 ){
   return num1;
  }else{
   return num2;
  }  
 }
 
 public static void printno(){  
  for(int counter = 1; counter <= 10; counter++){
   if(counter == 5){
    return;
   }
   System.out.println(counter);
  }  
 } 

}