439,968 views
2 votes
2 votes
Write a program that displays the middle value of three unduplicated input values. Hint: Review the four solutions in the smallest number case study in this chapter. Consider how easy or hard it would be to modify each of those algorithms to find the middle value rather than the smallest value. Then modify the algorithm you consider most appropriate for this problem.

User Sergserg
by
2.9k points

1 Answer

16 votes
16 votes

Answer:

The code is in java.

Step-by-step explanation:

import java.util.Scanner;

class Main{

public static void main(String[] args) {

System.out.println("Enter 3 different numbers");

Scanner obj = new Scanner(System.in);

int a = obj.nextInt();

int b = obj.nextInt();

int c = obj.nextInt();

System.out.println("The middle element is : ");

//Check if a is the middle

if(a>b&&a<c || a>c&&a<b){

System.out.println(a);

}

//Check if b is the middle element

else if(b>a&&b<c || b<a&&b>c){

System.out.println(b);

}

else{

System.out.println(c);

}

}

}

OUTPUT:-

Write a program that displays the middle value of three unduplicated input values-example-1
User Stenal P Jolly
by
2.6k points