Write a java user defined method called minimum that finds t

Write a java user defined method called minimum that finds the smallest of 3 numbers by passing in 3 integers and returning the value of the smallest number ( use the Math method in your user defined method). If your program had

System.out.print(minimum (5,-1,-2));

what would be the output to the user?

Solution

MInTest.java


public class MInTest {

   public static void main(String[] args) {
       System.out.print(minimum (5,-1,-2));
   }
   public static int minimum (int a, int b, int c){
       if(Math.min(a, b) == a && Math.min(a,c) == a){
           return a;
       }
       else{
           if(Math.min(c, b) == b){
               return b;
           }
           else{
               return c;
           }
       }
   }

}

Output:

-2

Write a java user defined method called minimum that finds the smallest of 3 numbers by passing in 3 integers and returning the value of the smallest number ( u

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site