"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