
Return to Unit
Menu | Java Main Page |
MathBits.com |
Terms
of Use
Methods -- Style 4
Style 4:
Our fourth style of method takes arguments AND returns a value.
//Demo
Program for Methods
import java.io.*;
import BreezyGUI.*;
public class method1test
{
public static void main(String[ ] args)
{
int test1 = 12, test2 =
10;
//
notice in this next line the method called min
System.out.println("The minimum
of " + test1 + " and " + test2
+ " is " + min(test1,test2) + ".");
}
//Method to find minimum
// This method needs to receive two integers and
returns one integer.
public static int min(int x, int y)
{
int minimum;
// local variable
if (x < y)
minimum = x;
else
minimum = y;
return (minimum);
// return value to main
}
}
Output:
The minimum of 12 and 10 is 10. |

Return to Unit
Menu | Java Main Page |
MathBits.com |
Terms
of Use
|