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