Java rewrite "C Classic 100 Questions"--05

Source: Internet
Author: User

"Program 5"
Title: Enter three integers x, y, Z, please put these three numbers from small to large output.
1. Procedure analysis: We find a way to put the smallest number on the X, first compare x with Y, if x>y the value of x and Y to Exchange, and then with X and Z to compare, if X>z will be x and Z of the value of the exchange, this can make x minimum.
2. Program Source code:

1 ImportJava.util.Scanner;2 3 /*this article transferred from blog: www.cnblogs.com/java-1004 "program 5"5 title: Enter three integers x, y, Z, please put these three numbers from small to large output. 6 Program Analysis: We try to put the smallest number on the X, first compare x with Y, if x>y the value of x and Y, and then compare X with Z, if x>z the value of X and Z, this will make x the smallest. 7  */8 9  Public classJava05 {Ten  One      Public Static voidMain (string[] args) { ASystem.out.print ("Please enter three integers in x, y, Z, separated by a space:"); -Scanner Scanner =NewScanner (system.in); -         intx =scanner.nextint (); the         inty =scanner.nextint (); -         intz =scanner.nextint (); - scanner.close (); -System.out.print (x + "," + y + "," + z + "in ascending order:"); +         if(X >y) { -             inttemp =x; +x =y; Ay =temp; at         } -         if(X >z) { -             inttemp =x; -x =Z; -z =temp; -         } in         if(Y >z) { -             inttemp =y; toy =Z; +z =temp; -         } theSystem.out.print (x + "," + y + "," +z); *     } $}

Java rewrite "C Classic 100 Questions"--05

Related Article

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.