Pořadí čísel podle velikosti


/ Published in: Java
Save to your folder(s)

Napište program, který seřadí (3) zadaná čísla podle velikosti od největšího po nejmenší.

(Pzn.: šlo by pravděpodobně řešit mnohem lépe než je uvedeno)


Copy this code and paste it in your HTML
  1. import java.util.Scanner;
  2.  
  3. public class Cviceni­3{
  4. public static void main(String[] args){
  5. Scanner sc = new Scanner(System.in);
  6. System.out.println("Zadej postupne 3 ci­sla, po kazdemm stiskni ENTER");
  7. int a = sc.nextInt();
  8. int b = sc.nextInt();
  9. int c = sc.nextInt();
  10.  
  11. if(a > b){
  12. if(b > c){
  13. System.out.println("Poradi­: "+a+" "+b+" "+c);
  14. }
  15.  
  16. }else{ //(b > a)
  17. if(a > c){
  18. System.out.println("Poradi­: "+b+" "+a+" "+c);
  19. }else{
  20. if(c > b){
  21. System.out.println("Poradi: "+c+" "+b+" "+a);
  22. }
  23. }
  24. }if(a > c){
  25. if(c > b){
  26. System.out.println("Poradi­: "+a+" "+c+" "+b);
  27. }
  28. }else{ //(c > a)
  29. if(a > b){
  30. System.out.println("Poradi: "+c+" "+a+" "+b);
  31. }else{
  32. if(b > c){
  33. System.out.println("Poradi­: "+b+" "+c+" "+a);
  34. }
  35. }
  36. }
  37. }
  38. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.