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/6ce9fa6be18eb7d2c5388a07f8e77749 to your computer and use it in GitHub Desktop.
Save krlakshmikanth/6ce9fa6be18eb7d2c5388a07f8e77749 to your computer and use it in GitHub Desktop.
Sort 3 Integers without using if condition.
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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment