Hello and Good Evening Everyone!!!!
Please solve the Program 9.5 in JAVA language.
Class-9(CICSE)
Subject-Computer Science.
Answers
{
public static int median(int a,int b,int c){
return (int)(Math.min(Math.min(Math.max(a,b), Math.max(b,c)),Math.max(a,c)));
}
public static void main(String[] args) {
System.out.println(Test.median(7,3,9));
System.out.println(Test.median(29,-14,11));
}
}
Hey there!
Here's your code.
// Java program to print the middle value of the three integer using if - else statement
// Written by Mahnaz
public class MiddleValue
{
public static int median(int a, int b, int c)
{
if (a > b)
{
if (b > c)
return b;
else if (a > c)
return c;
else
return a;
}
else
{
if (a > c)
return a;
else if (b > c)
return c;
else
return b;
}
}
public static void main(String[] args)
{
System.out.println(median(1, 2, 3));
System.out.println(median(1, 3, 2));
System.out.println(median(2, 1, 3));
System.out.println(median(2, 3, 1));
System.out.println(median(3, 1, 2));
System.out.println(median(3, 2, 1));
}
}
_______________________________
See the attachment for proper review.
_______________________________