Java exercise: Sort numbers with if ()

Source: Internet
Author: User

Import Java.util.Scanner;

/**

    • Created by Administrator on 2018/4/19 0019.
      /
      /

      *compare.java

      • Compare input to size and output
      • V.1
        */
        public class Compare {
        public static void Main (string[] args) {
        Scanner input=new Scanner (system.in);
        int num1,num2,num3,a,b,c;
        System.out.println ("Please enter the value of A,b,c:");

        System.out.println ("A:"); Enter three numbers first and store
        Num1=input.nextint ();
        System.out.println ("B:");
        Num2=input.nextint ();
        System.out.println ("C:");
        Num3=input.nextint ();

        if (num1>=num2) {//numeric comparison and sorting
        if (NUM3>=NUM1) {
        c=num3;b=num1;a=num2;
        }else if (num3>=num2) {
        c=num1;b=num3;a=num2;
        }else{
        C=NUM1;B=NUM2;A=NUM3;
        }
        } else{
        if (num3>=num2) {
        C=NUM3;B=NUM2;A=NUM1;
        }else if (NUM3>=NUM1) {
        C=NUM2;B=NUM3;A=NUM1;
        }else{
        C=NUM2;B=NUM1;A=NUM3;
        }
        }

        System.out.println ("After comparison a,b,c from small to large is: A=" +a+ ", b=" +b+ ", c=" +c "); Output sorted numbers

      }
      }

Java exercise: Sort numbers with if ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.