Methods often require more than one piece of information to perform their tasks. We now
consider how to write your own methods with multiple parameters.
use a method called maximum to determine and return the largest of three
double values. In main,
here is the program :
import java.util.Scanner;
public class Apples {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("Enter 3 floating point values seperated by spaces");
double number1 = input.nextDouble();
double number2 = input.nextDouble();
double number3 = input.nextDouble();
double result = maximum (number1,number2,number3);
System.out.println("maximum is " + result);
}
public static double maximum ( double x , double y, double z){
double maximumValue = x;
if (y > maximumValue)
maximumValue = y;
if (z > maximumValue)
maximumValue =z;
return maximumValue;
}
I look forward to the next class , this was a good class .
ReplyDelete