home
search
help
profile
liking the experience? our app is even better
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now  
showing results for how to get smallest number between two numbers in java
1import java.util.Scanner;
2
3public class Main {
4
5    public static void main(String[] args) {
6
7        Scanner scanner = new Scanner(System.in);
8
9        int greatest;
10        int smallest;
11
12        System.out.print("Enter three numbers: ");
13        int num1 = scanner.nextInt();
14        int num2 = scanner.nextInt();
15        int num3 = scanner.nextInt();
16
17        if(num1 > num2 && num1 > num3)
18            greatest =num1;
19
20        else if(num2 > num1 && num2 > num3)
21            greatest =num2;
22
23        else
24            greatest = num3;
25
26        if(num1 < num2 && num1 < num3)
27            smallest =num1;
28
29        else if(num2 < num1 && num2 < num3)
30            smallest =num2;
31
32        else
33            smallest = num3;
34
35        int difference = greatest - smallest;
36
37        System.out.printf("The difference of %d and %d is %d ",greatest,smallest,difference);
38    }
39}
upvote
downvote