Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Demo{
- public static void main(String[] args) {
- // TODO code application logic here
- // Variables for user Input
- int a , b , c , d , e ;
- // Variables to be found
- int min_integer = 0,mid_low_integer = 0,mid_integer = 0,mid_high_integer = 0,max_integer = 0;
- // Reading Five integers from console screen
- Scanner sc = new Scanner(System.in);
- System.out.println("Please enter five integers in a row");
- a = sc.nextInt();
- b = sc.nextInt();
- c = sc.nextInt();
- d = sc.nextInt();
- e = sc.nextInt();
- // Your code goes here
- max_integer = Math.max( a, ( Math.max ( b , Math.max ( c , Math.max ( d , e ) ) ) ) ) ;
- min_integer = Math.min ( a, ( Math.min ( b , Math.min ( c , Math.min ( d , e ) ) ) ) ) ;
- mid_high_integer = Math.min( Math.max(Math.max(Math.max(a,b),Math.max(b,c)),Math.max(Math.max(b,c),Math.max(c,d))) ,
- Math.min(Math.max(Math.max(Math.max(b,c),Math.max(c,d)),Math.max(Math.max(c,d),Math.max(d,e))),Math.min(Math.max(Math.max(Math.max(c,d),Math.max(d,e)),Math.max(Math.max(d,e),Math.max(e,a))),Math.min(Math.max(Math.max(Math.max(d,e),Math.max(e,a)),Math.max(Math.max(e,a),Math.max(a,b))),Math.max(Math.max(Math.max(e,a),Math.max(a,b)),Math.max(Math.max(a,b),Math.max(b,c)))))) );
- mid_low_integer = Math.max( Math.min(Math.min(Math.min(a,b),Math.min(b,c)),Math.min(Math.min(b,c),Math.min(c,d))) , Math.max(Math.min(Math.min(Math.min(b,c),Math.min(c,d)),Math.min(Math.min(c,d),Math.min(d,e))),Math.max(Math.min(Math.min(Math.min(c,d),Math.min(d,e)),Math.min(Math.min(d,e),Math.min(e,a))),Math.max(Math.min(Math.min(Math.min(d,e),Math.min(e,a)),Math.min(Math.min(e,a),Math.min(a,b))),Math.min(Math.min(Math.min(e,a),Math.min(a,b)),Math.min(Math.min(a,b),Math.min(b,c)))))) );
- mid_integer = a + b + c + d + e - max_integer - mid_high_integer - min_integer - mid_low_integer ;
- // to Here
- // Printing out the result -- Sorted Array
- System.out.println(min_integer + " " + mid_low_integer + " " + mid_integer + " " + mid_high_integer + " " + max_integer);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement