Advertisement
Alrarapie

Urutan terkecil

Oct 21st, 2021
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main2 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int a = scanner.nextInt();
  7.         int b = scanner.nextInt();
  8.         int c = scanner.nextInt();
  9.  
  10.         if (a<b&&a<c){
  11.             if (b<c) System.out.printf("%d,%d,%d\n",a,b,c);
  12.             else System.out.printf("%d,%d,%d\n",a,c,b);
  13.         }else if (b<a&&b<c){
  14.             if (a<c) System.out.printf("%d,%d,%d\n",b,a,c);
  15.             else System.out.printf("%d,%d,%d\n",b,c,a);
  16.         }else {
  17.             if (a<b) System.out.printf("%d,%d,%d\n",c,a,b);
  18.             else System.out.printf("%d,%d,%d\n",c,b,a);
  19.         }
  20.  
  21.  
  22.         /*
  23.             Atau cara yang lain
  24.          */
  25. //        int tmp;
  26. //        if (a > b) {
  27. //            tmp = a;
  28. //            a = b;
  29. //            b = tmp;
  30. //        }
  31. //        if (a > c) {
  32. //            tmp = a;
  33. //            a = c;
  34. //            c = tmp;
  35. //        }
  36. //        if (b > c) {
  37. //            tmp = b;
  38. //            b = c;
  39. //            c = tmp;
  40. //        }
  41. //        System.out.printf("%d,%d,%d",a,b,c);
  42.     }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement