Created
March 30, 2017 12:57
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Given three integers, print them in sorted order without 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