Statement Exercises 5

Source: Internet
Author: User

Enter three integers x, y, Z, please put these three numbers from small to large output.

1Scanner SC2 =NewScanner (system.in);2System.out.println ("Please enter the first number:");3         intx =sc2.nextint ();4System.out.println ("Please enter a second number:");5         inty =sc2.nextint ();6System.out.println ("Please enter a third number:");7         intz =sc2.nextint ();8         if(X >y) {9             intTe =x;Tenx =y; Oney =te; A         } -         if(Z > x && z <y) { -System.out.println ("Three numbers from small to large": "+ x +" "+ z +" "+y); the}Else if(Z >y) { -System.out.println ("Three numbers from small to large": "+ x +" "+ y +" "+z); -}Else if(Z <x) { -System.out.println ("Three numbers from small to large": "+ z +" "+ x +" "+y); +}

Result: Because there are only three numbers, it is not necessary to use a sort algorithm such as bubble sorting, as long as the first two numbers are compared and inserted into the output of the third number.

Statement Exercises 5

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.