Skip to content

Instantly share code, notes, and snippets.

@krlakshmikanth
Created March 30, 2017 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krlakshmikanth/3c914580fb414d7fc8901070c71c8be7 to your computer and use it in GitHub Desktop.
Save krlakshmikanth/3c914580fb414d7fc8901070c71c8be7 to your computer and use it in GitHub Desktop.
Sort 3 Integers without using if condition. Examples Input : a = 3, b = 2, c = 9 Output : 2 3 9 Input : a = 4, b = 1, c = 9 Output : 1 4 9
import java.util.Scanner;
import java.lang.Math;
class Main {
public static void main(String[] args)
{
int a,b,c;
Scanner sc = new Scanner(System.in);
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
int big = Math.max(a,Math.max(b,c));
int small = Math.min(a,Math.min(b,c));
int mid = ((a+b+c)-(big+small));
System.out.println(small);
System.out.println(mid);
System.out.println(big);
}
}
@krlakshmikanth
Copy link
Author

Given three inte­gers, print them in sorted order with­out using if condition.

Input : a = 3, b = 2, c = 9
Output : 2 3 9

Input : a = 4, b = 1, c = 9
Output : 1 4 9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment